[R] Running an ANOVA with a BY

David Winsemius dwinsemius at comcast.net
Mon Sep 28 21:21:00 CEST 2009


On Sep 28, 2009, at 11:39 AM, 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.
>
Since you have not offered a reproducible example, we are left to  
choose our own. Checking the help page for "by" we see that a problem  
extremely similar to yours is already solved. I choose not to attach()  
the data for well-understood reasons:

anova.LMH <- by(warpbreaks, warpbreaks$tension, function(x) aov(breaks  
~ wool, data=x) )


> 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;



David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list