I've got a newbie question and I got a little lost in the "table helps". I've got a data.frame I would like to summarize as a (and pardon for the lack of correct vernacular) data collection matrix. My data looks like, stand siteindex age acres pct.acres 1 232 116 45 8477.3105 0.56159458 2 234 121 25 11120.1530 0.73667441 3 235 132 25 5399.4605 0.35769691 4 236 115 5 6308.3969 0.41791103 5 240 116 45 473.1533 0.03134489 6 241 116 15 21790.9595 1.44358105 7 245 171 25 686.9867 0.04551066 8 246 134 25 15176.8082 1.00541478 9 247 99 35 1754.9282 0.11625835 10 251 125 55 7396.1098 0.48996851 ...blah, blah, blah... and when I attempt to create a summary table using aggregate, I get the following results,> aggregate( stands$acres, by=list(stands$age,stands$siteindex), sum )Group.1 Group.2 x 1 95 86 6403.5457 2 5 88 1517.6781 3 45 88 3555.3213 4 125 89 6269.2633 5 95 90 3154.3531 6 55 93 14006.9781 7 15 94 98.9918 8 35 94 2241.0531 9 105 94 431.0281 but what I really want is a matrix where the rows and columns are classes (in increments of 5 or 10 or whatever) and the cells are the sums (or means or whatever) for the data.frame. I guess it would be equivalent to like surf.ls/surf.gls without fitting a trend but that would also allow me to plot the results graphically in addition to simply printing out the table using xtable. Jeff. --- Jeff D. Hamann Forest Informatics, Inc. PO Box 1421 Corvallis, Oregon USA 97339-1421 541-754-1428 jeff.hamann at forestinformatics.com www.forestinformatics.com
Check out aggregate.table in package gregmisc . Jeff D. Hamann <jeff.hamann <at> forestinformatics.com> writes: : : I've got a newbie question and I got a little lost in the "table helps". : I've got a data.frame I would like to summarize as a (and pardon for the : lack of correct vernacular) data collection matrix. My data looks like, : : stand siteindex age acres pct.acres : 1 232 116 45 8477.3105 0.56159458 : 2 234 121 25 11120.1530 0.73667441 : 3 235 132 25 5399.4605 0.35769691 : 4 236 115 5 6308.3969 0.41791103 : 5 240 116 45 473.1533 0.03134489 : 6 241 116 15 21790.9595 1.44358105 : 7 245 171 25 686.9867 0.04551066 : 8 246 134 25 15176.8082 1.00541478 : 9 247 99 35 1754.9282 0.11625835 : 10 251 125 55 7396.1098 0.48996851 : ...blah, blah, blah... : : and when I attempt to create a summary table using aggregate, I get the : following results, : : > aggregate( stands$acres, by=list(stands$age,stands$siteindex), sum ) : : Group.1 Group.2 x : 1 95 86 6403.5457 : 2 5 88 1517.6781 : 3 45 88 3555.3213 : 4 125 89 6269.2633 : 5 95 90 3154.3531 : 6 55 93 14006.9781 : 7 15 94 98.9918 : 8 35 94 2241.0531 : 9 105 94 431.0281 : : but what I really want is a matrix where the rows and columns are classes : (in increments of 5 or 10 or whatever) and the cells are the sums (or means : or whatever) for the data.frame. I guess it would be equivalent to like : surf.ls/surf.gls without fitting a trend but that would also allow me to : plot the results graphically in addition to simply printing out the table : using xtable. : : Jeff. : : --- : Jeff D. Hamann : Forest Informatics, Inc. : PO Box 1421 : Corvallis, Oregon USA 97339-1421 : 541-754-1428 : jeff.hamann <at> forestinformatics.com : www.forestinformatics.com : : ______________________________________________ : R-help <at> stat.math.ethz.ch mailing list : https://www.stat.math.ethz.ch/mailman/listinfo/r-help : PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html : :