[R] summing and combining rows
Christopher R. Dolanc
crdolanc at ucdavis.edu
Tue Aug 7 19:47:40 CEST 2012
Hello,
I have a data set that needs to be combined so that rows are summed by a
group based on a certain variable. I'm pretty sure rowsum() or rowsums()
can do this but it's difficult for me to figure out how it will work for
my data based on the examples I've read.
My data are structured like this:
Plot SizeClass Stems
12 Class3 1
12 Class4 3
17 Class3 5
17 Class4 2
I simply want to sum the size classes by plot and create a new data
frame with a size class called "Class34" or with the SizeClass variable
removed. I actually do have other size classes that I want to leave
alone, but combine 3 and 4, so if I could figure out how to do this by
creating a new class, that would be preferable.
I've also attached a more detailed sample of data.
Thanks,
Chris Dolanc
--
Christopher R. Dolanc
Post-doctoral Researcher
University of Montana and UC-Davis
-------------- next part --------------
Data Plot Lat LatCat Elevation ElevCat Type SizeClass Stems Area Density
5171 VTM 39C16 39.76282 Lat6 1500 Elev1 Conifer Class3 0 751.5347 0.00000
5172 VTM 39C16 39.76282 Lat6 1500 Elev1 Conifer Class4 1 751.5347 13.30611
5771 VTM 39F11 39.57721 Lat6 500 Elev1 Conifer Class3 0 751.5347 0.00000
5772 VTM 39F11 39.57721 Lat6 500 Elev1 Conifer Class4 0 751.5347 0.00000
5787 VTM 39F13 39.56214 Lat6 1500 Elev1 Conifer Class3 3 694.0784 0.00000
5788 VTM 39F13 39.56214 Lat6 1500 Elev1 Conifer Class4 1 694.0784 0.00000
5795 VTM 39F14 39.54522 Lat6 900 Elev1 Conifer Class3 1 763.9850 13.08926
5796 VTM 39F14 39.54522 Lat6 900 Elev1 Conifer Class4 2 763.9850 0.00000
More information about the R-help
mailing list