Skip to content
Prev 302658 / 398506 Next

summing and combining rows

HI,

I tried two ways in aggregate.? The results are the same.
dat1<-read.table(text="
?? Data?????????? Plot????? Lat LatCat Elevation ElevCat??? Type SizeClass Stems???? Area?? Density
?? VTM????????? 39C16 39.76282?? Lat6????? 1500?? Elev1 Conifer??? Class3???? 0 751.5347?? 0.00000
?? VTM????????? 39C16 39.76282?? Lat6????? 1500?? Elev1 Conifer??? Class4???? 1 751.5347? 13.30611
?? VTM????????? 39F11 39.57721?? Lat6?????? 500?? Elev1 Conifer??? Class3???? 0 751.5347?? 0.00000
?? VTM????????? 39F11 39.57721?? Lat6?????? 500?? Elev1 Conifer??? Class4???? 0 751.5347?? 0.00000
?? VTM????????? 39F13 39.56214?? Lat6????? 1500?? Elev1 Conifer??? Class3???? 3 694.0784?? 0.00000
?? VTM????????? 39F13 39.56214?? Lat6????? 1500?? Elev1 Conifer??? Class4???? 1 694.0784?? 0.00000
?? VTM????????? 39F14 39.54522?? Lat6?????? 900?? Elev1 Conifer??? Class3???? 1 763.9850? 13.08926
?? VTM????????? 39F14 39.54522?? Lat6?????? 900?? Elev1 Conifer??? Class4???? 2 763.9850?? 0.00000
",sep="",header=TRUE, stringsAsFactors=FALSE)
? Group.1 Group.2? Group.3 Group.4 Group.5 Group.6? Group.7? Group.8 x
1?? 39F13???? VTM 39.56214??? Lat6??? 1500 Conifer 694.0784? 0.00000 4
2?? 39F11???? VTM 39.57721??? Lat6???? 500 Conifer 751.5347? 0.00000 0
3?? 39C16???? VTM 39.76282??? Lat6??? 1500 Conifer 751.5347? 0.00000 0
4?? 39F14???? VTM 39.54522??? Lat6???? 900 Conifer 763.9850? 0.00000 2
5?? 39F14???? VTM 39.54522??? Lat6???? 900 Conifer 763.9850 13.08926 1
6?? 39C16???? VTM 39.76282??? Lat6??? 1500 Conifer 751.5347 13.30611 1
?? Plot Data????? Lat LatCat Elevation??? Type???? Area? Density Stems
1 39F13? VTM 39.56214?? Lat6????? 1500 Conifer 694.0784? 0.00000???? 4
2 39F11? VTM 39.57721?? Lat6?????? 500 Conifer 751.5347? 0.00000???? 0
3 39C16? VTM 39.76282?? Lat6????? 1500 Conifer 751.5347? 0.00000???? 0
4 39F14? VTM 39.54522?? Lat6?????? 900 Conifer 763.9850? 0.00000???? 2
5 39F14? VTM 39.54522?? Lat6?????? 900 Conifer 763.9850 13.08926???? 1
6 39C16? VTM 39.76282?? Lat6????? 1500 Conifer 751.5347 13.30611???? 1



The rows with 39.57721 and 39.56214 are the same for SizeClass except the Stems #.? It got summed.? Otherwise, it is giving both Class3 and Class4 values separately.

A.K.








----- Original Message -----
From: Christopher R. Dolanc <crdolanc at ucdavis.edu>
To: arun <smartpink111 at yahoo.com>
Cc: 
Sent: Tuesday, August 7, 2012 6:38 PM
Subject: Re: [R] summing and combining rows

Hmmm. It looks like it's only giving me the values for Class3, instead 
of summing, which is why I thought the "+" method might not be the 
appropriate coding.

Here's the code I used:
aggregate(Stems~Plot+Data+Lat+LatCat+Elevation+Type+Area+Density, 
data=CH_Con_Elev1SC34, sum)
SizeClass=rep("Class34",))

If it helps, attached is a txt file with the data structure.
On 8/7/2012 3:00 PM, arun wrote: