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
functions(t.test) on variables by groups
2 messages · Hai Lin, Peter Dalgaard
Hai Lin <kevinvol2002 at yahoo.com> writes:
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.
Something like this? lapply(zot[-1],function(x)t.test(x~zot$Groups))
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907