I have a data.frame with the following: ID Species Count 1 A 3 1 B 2 1 E 12 2 A 13 2 C 5 2 F 4 3 B 5 3 D 3 I need it in this format: ID A B C D E F 1 3 2 0 0 12 0 2 13 0 5 0 0 4 3 0 5 0 3 0 0 Any ideas? -- View this message in context: http://n4.nabble.com/should-be-easy-data-frame-manipulation-tp1457518p1457518.html Sent from the R help mailing list archive at Nabble.com.
On Jan 30, 2010, at 12:00 PM, Brad Patrick Schneid wrote:> > I have a data.frame with the following: > > ID Species Count > 1 A 3 > 1 B 2 > 1 E 12 > 2 A 13 > 2 C 5 > 2 F 4 > 3 B 5 > 3 D 3 > > I need it in this format: > > ID A B C D E F > 1 3 2 0 0 12 0 > 2 13 0 5 0 0 4 > 3 0 5 0 3 0 0Assuming the dataframe is called dtt: > xtabs(Count ~ ID + Species, data=dtt) Species ID A B C D E F 1 3 2 0 0 12 0 2 13 0 5 0 0 4 3 0 5 0 3 0 0>David Winsemius, MD Heritage Laboratories West Hartford, CT
You rock! thank you.. you saved me hours of hunting around. -- View this message in context: http://n4.nabble.com/should-be-easy-data-frame-manipulation-tp1457518p1457675.html Sent from the R help mailing list archive at Nabble.com.
On Jan 30, 2010, at 4:38 PM, Brad Patrick Schneid wrote:> > You rock! > thank you.. you saved me hours of hunting around. > --You should read the r-help list more often. Gabor Grothendieck gave an example of the use of xtabs() this very morning. David Winsemius, MD Heritage Laboratories West Hartford, CT