Re: [R] aov or t-test applied on all variables of a data.frame

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Sat 12 Mar 2005 - 02:29:28 EST

On Fri, 11 Mar 2005, Christoph Lehmann wrote:

> Hi
> I have a data.frame with say 10 continuous variables and one grouping factor
> (say 3 levels)
>
> how can I easily (without loops) apply for each continous variable e.g. an
> aov, with the grouping factor as my factor (or if the grouping factor has 2
> levels, eg. a t-test)
>

You can call aov() or lm() with a multicolumn response variable.
> summary(aov(cbind(y1,y2,y3)~factor(x),data=df))
  Response y1 :

             Df Sum Sq Mean Sq F value Pr(>F) factor(x) 2 0.187 0.093 0.0735 0.9293 Residuals 27 34.326 1.271

  Response y2 :

             Df Sum Sq Mean Sq F value Pr(>F) factor(x) 2 0.133 0.066 0.0497 0.9516 Residuals 27 36.107 1.337

  Response y3 :

             Df Sum Sq Mean Sq F value Pr(>F) factor(x) 2 6.051 3.026 2.5605 0.09589 . Residuals 27 31.903 1.182

---
Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1


 	-thomas

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Mon Mar 14 10:34:08 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:47 EST