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

From: Hai Lin <kevinvol2002_at_yahoo.com>
Date: Wed 13 Apr 2005 - 01:44:08 EST


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



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 Wed Apr 13 01:50:43 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:07 EST