[R] functions(t.test) on variables by groups

Hai Lin kevinvol2002 at yahoo.com
Tue Apr 12 17:44:08 CEST 2005


Dear R users,

I have a data frame with categorical Vars. "Groups"
and a couple  columns of numeric Vars. I am trying to
make two-sample t.test on each variable(s01-s03) by
Groups.

A data generated as following:

zot <- data.frame(Groups=rep(letters[1:2], each=4),
s01=rnorm(8), s02=rnorm(8), s03=rnorm(8))

I have written a piece with a for loop. 
for (i in 1:(length(zot)-1)) {
	print(t.test(zot[,i+1]~zot[,1]))
	            }

I wish something can be easier extracted or can save
it within for loop, or not even using for loop.  

Thanks in advance for your help.

Kevin




More information about the R-help mailing list