[R] sum data from data.frame in a matrix

Nicolas Gutierrez nicolasg at uw.edu
Wed Feb 23 08:30:08 CET 2011


Hi all (again),

I have a data frame "pop":

    xloc  yloc  yield
1  10	 12    95
2  11	 10    81
3  12	 11    20
4  12	 11    10

And I want to get the sum of yield for the cell (pop$xloc, pop$yloc) in 
a matrix as follows:

             xloc
           10  11  12
        10 0   81  0
  yloc  11 0   0   30
        12 95  0   0


Any ideas? thanks!

Nico



More information about the R-help mailing list