[R] folding table into a matrix

Gene Cutler gcutler at amgen.com
Thu Sep 23 21:59:24 CEST 2004


I'm just getting started with R, so feel free to point me to the 
appropriate documentation if this is already answered somewhere (though 
I've been unable to find it myself).  This does seem like a rather 
basic question.
I want to fold a table into a matrix.  The table is formatted like so:

Column_Index  Value
1             486
2             688
3             447
4             555
5             639
1             950
2             881
3             1785
4             1216
1             612
2             790
3             542
4             1310
5             976

And I want to end up with something like this:

       [,1]  [,2]  [,3]  [,4]  [,5]
[1,]   486   688   447   555   639
[2,]   950   881  1785  1216    NA
[3,]   612   790   512  1310   976

Since not all the rows are complete, I can't just reformat using 
matrix(), I need to go by the index information in the Column_Index 
column.  This seems like something simple to do, but I'm stumped.

Thanks.

-- Gene




More information about the R-help mailing list