You should be able to obtain this by just using lapply
:
lapply(df[,2:ncol(df)], function(x) t.test(x ~ df$Uttaxeringskassa))
Which will give you a list of the resulting t.test
results:
$Delägare.Totalt
Welch Two Sample t-test
data: x by df$Uttaxeringskassa
t = -5.0681, df = 6.294, p-value = 0.001991
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-405.4746 -143.4302
sample estimates:
mean in group 0 mean in group 1
113.7143 388.1667
$Delägare.AndelKvinnor
Welch Two Sample t-test
data: x by df$Uttaxeringskassa
t = 0.4533, df = 6.37, p-value = 0.6654
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-7.495586 10.963260
sample estimates:
mean in group 0 mean in group 1
15.30886 13.57503
$Utgifter.SjukhjälpPerMedlem
Welch Two Sample t-test
data: x by df$Uttaxeringskassa
t = -2.4988, df = 8.246, p-value = 0.03618
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-6.5178601 -0.2783456
sample estimates:
mean in group 0 mean in group 1
3.936402 7.334505