I am trying to perform a difference of means test in R, but I get the following error:
Error in t.test.formula(age ~ fare, data = FARE, var.equal = TRUE) : grouping factor must have exactly 2 levels
This is the exercise question:
Perform an appropriate bivariate statistical test to explore the relationship between age and fare. Provide command(s) to perform the analysis. (Hint: I am not asking you to run a regression.)
This is my code:
td
is my data set
FARE <- td[is.na(td$fare) == FALSE & is.na(td$age) == FALSE, ]
by(data = FARE$fare, # This part provides Y (data)
INDICES = FARE$age, # This part provides X (indices)
FUN = summary) # This part provides what you want to do (function).
t.test (age ~ fare, #X and Y specification
data = FARE, #This part provides the data frame
var.equal = TRUE) # This option tells R to assume equal variance.
Thanks