[R] Function for multiple t tests

Iuri Gavronski iuri at ufrgs.br
Sat Jan 21 22:40:31 CET 2012


Hi,

I want to run t.test() for several variables among two groups, and I
would like to skip the tedious process of collecting information to
assemble a table, but I am not sure if the function I want already
exists. Any suggestion would be appreciated.

I have a working example, as required by the posting guide:

my_swiss = swiss[-1,]
my_swiss$facto = rep(1:2,nrow(my_swiss)/2)
t.test(Fertility~facto,data=my_swiss)
by(my_swiss$Fertility,my_swiss$facto, sd)
t.test(Agriculture~facto,data=my_swiss)
by(my_swiss$Agriculture,my_swiss$facto, sd)


ttable <- function(formula, data) { ???? }

ttable(Fertility + Agriculture ~ facto, data=my_swiss)

facto              1                          2
             Mean  s.d.                  Mean s.d.  t-test p-value
Fertility      69.19 10.66               70.66 14.38 -0.39  0.70
Agriculture    51.65 21.15               51.13 24.05 0.08 0.94



More information about the R-help mailing list