0

I plan to do t.test for q1,q2,q3 by group A&B in df

q1 q2 q3 group
1  0  1  A
0  1  0  B
1  1  1  C
0  1  0  B

If only 2groups, I can use t.test(q1~group,df) lapply(d[,-4], function(i) t.test(i ~ d$group)),but how to do t.test between group A & B when I have 3 groups?

jackson883
  • 71
  • 9
  • If looking to test equality of means across more than two groups, you could use the F test. This test is sensitive to departures from normality. A non-parametric analog is the quade test: `?quade.test`. – lmo Nov 01 '16 at 13:06
  • i only want to compare 2 groups `A&B`,the T test is best, but R's function has no option to my experiment. – jackson883 Nov 01 '16 at 13:10
  • In that case, restrict the data set in the first argument to only include groups A and B: `lapply(d[d$group %in% c("A", "B"),-4], function(i) t.test(i ~ d$group))`. – lmo Nov 01 '16 at 13:12
  • Have a look here: http://stackoverflow.com/questions/37474672/looping-through-t-tests-for-data-frame-subsets-in-r/37479506#37479506 – coffeinjunky Nov 01 '16 at 13:17

0 Answers0