[R] Running an ANOVA with a BY

David Scott d.scott at auckland.ac.nz
Mon Sep 28 22:24:01 CEST 2009


baxterj wrote:
> I have a simple 1 way anova coded like
> 
> summary(ANOVA1way <- aov(Value ~ WellID, data = welldata))
> 
> How can I use the BY function to do this ANOVA for each group using another
> variable in the dataset??  I tried coding it like this, but it doesn't seem
> to work.
> 
> summary(ANOVA1way <- by(welldata, Analyte, function(x) aov(Value ~ WellID,
> data = welldata)))
> 
> In SAS I would code it like this:
> Proc sort data=welldata; by analyte; run;
> Proc glm data=welldata;
> by analyte;
> class wellid;
> model value = wellid;
> run;
> 
> 
> Any suggestions??? 


Given you have asked two questions on translating SAS idioms to R, you 
might be a candidate for Bob Muenchen's book which some people have 
previously recommended:

[3]	 Robert A. Muenchen. R for SAS and SPSS Users. Springer Series in 
Statistics and Computing. Springer, 2009. ISBN: 978-0-387-09417-5. [ bib 
| Discount Info | Publisher Info ]
This book demonstrates which of the add-on packages are most like SAS 
and SPSS and compares them to R's built-in functions. It steps through 
over 30 programs written in all three packages, comparing and 
contrasting the packages' differing approaches. The programs and 
practice datasets are available for download.

David Scott



-- 
_________________________________________________________________
David Scott	Department of Statistics
		The University of Auckland, PB 92019
		Auckland 1142,    NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:	d.scott at auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics




More information about the R-help mailing list