[R] Grouping by factors in R

Christopher R. Dolanc crdolanc at ucdavis.edu
Tue Feb 8 20:54:38 CET 2011


I'm having a hard time figuring out how to group results by certain 
factors in R.  I have data with the following headings:

[1] "Time"      "Plot"      "LatCat"    "Elevation" "ElevCat"   
"Aspect"    "AspCat"    "Slope"
[9] "SlopeCat"  "Species"   "SizeClass" "Stems"

and I'm trying to use a GLM to test differences in "Stems" for different 
categories/factors - most importantly, I want to group things so that I 
see results by "SizeClass" and then by "Species".  This is pretty easy 
in SAS using the "Group By" command, but in R, I haven't figured it out.

I've tried using the following code:

 > stems139GLM <- glm(Stems ~ Time | SizeClass | Species, 
family=poisson, data=stems139)

but R gives me this message:

Error in pmax(exp(eta), .Machine$double.eps) :
   cannot mix 0-length vectors with others
In addition: Warning messages:
1: In Ops.factor(Time, SizeClass) : | not meaningful for factors
2: In Ops.factor(Time | SizeClass, Species) : | not meaningful for factors

I'd appreciate any help.

Thanks.

-- 
Christopher R. Dolanc
PhD Candidate
Ecology Graduate Group
University of California, Davis
Lab Phone: (530) 752-2644 (Barbour lab)un



More information about the R-help mailing list