R uses what is called "methods" to conduct different behavior depending on what kind of object is given to a function.
t.test(Head_IC~make, alternative= "two.sided", paired=T)
is different than
t.test(Head_IC, make, alternative= "two.sided", paired=T)
in that the first accepts a formula argument, where all the numeric data are in Head_IC
and all of the category data are in make
. The second form assumes that all of the numeric data for the first group are in Head_IC
and all of the numeric data for the second group are in make
.
This is beneficial because it allows you to conveniently get to the same result even though your data may have slightly different formats.
Unfortunately, as you've found, your data are not in a format that is suitable to using t.test
. There are a few ways you can approach this.
Subset your data
data_subset <- your_data_object[your_data_object$make %in% c("Ford", "Chevrolet"), ]
t.test(Head_IC~make, alternative= "two.sided", paired=T, data = data_subset)
Get two vectors
Ford <- your_data_object$Head_IC[your_data_object$make == "Ford"]
Chev <- your_data_object$Head_IC[your_data_object$make == "Chevrolet"]
t.test(Ford, Chev, alternative = "two.sided", paired = TRUE)
There are many, many ways you could approach your problem, and you may want to look at ways to subset and transform your data that work with whatever set of tools you are using.