title: How to convert a dataframe into a matrix using variables as the coordinate of the matrix?
body: <p>I have a data frame with 3 columns: </p>
  
  <pre><code>df&lt;-data.frame(x=c(1,1,1,2,2,2,2,3,3), y=c(1,2,3,1,2,3,4,1,2), percentage=c(50,25,25,15,35,25,25,55,45))
  </code></pre>
  
  <p>Looks like:</p>
  
  <pre><code>  x y percentage
  1 1 1         50
  2 1 2         25
  3 1 3         25
  4 2 1         15
  5 2 2         35
  6 2 3         25
  7 2 4         25
  8 3 1         55
  9 3 2         45
  </code></pre>
  
  <p>The third column represents the percentage of the area of y-ID objects (2 col) that are within the x-ID objects (1 col).</p>
  
  <p>I would like to get a matrix (or smthg related) with the x and y that define the coordinates/subscript and the "percentage", the elements of the matrix.</p>
  
  <p>Basically, I would like to get a matrix like that:</p>
  
  <pre><code>  1  2  3  4
  1 50 25 25 0
  2 15 35 25 25
  3 55 45 0  0
  </code></pre>
  
  <p>Is there an easy way to achieve this ?</p>