# How to test if one mean is greater than the other in R?

What would an appropriate test be for testing whether group 3 has a larger vital capacity than group 1 from the vitcap dataset in the ISwR package. This is what I was thinking so far, but I'm really not sure if this is the right test to use. Surely this is just showing whether the difference in means = 0 or not?

c = vitcap # Load the vitcap data
c # Displays the data
group1 = subset(c, c[,1]==1) # Creates a subset of group 1
group1 # Displays the subset
group3 = subset(c, c[,1]==3) # Creates a subset of group 3
group3 # Displays the subset
qqplot(group1[,2], group1[,3]) # Checking if the data is normally distributed
qqplot(group3[,2], group3[,3]) # Checking if the data is normally distributed

# The QQ Plots appear to show the data is normally distributed, thus we assume normality

t.test(group1[,3], group3[,3]) # 95% CI for the vital capacity of each group


Any help would be greatly appreciated.

• I would strongly recommend that you avoid naming your objects after common functions, c in particular... – nrussell Apr 15 '15 at 15:47
• If you need help choosing an appropriate statistical test, you should consult a statistician, not a programmer. Such discussions are better for Cross Validated rather than Stack Overflow. – MrFlick Apr 15 '15 at 15:53

t.test(rnorm(100, mean = 2, sd = 1), rnorm(100, mean = 0, sd = 1), alternative='greater')

Just change rnorms to group1[,3] and group3[,3] accordingly
wilcox.test(group1[,3], group3[,3], alternative="greater")