Basic – T-Test -> Grouping Factor Must have Exactly 2 Levels

are you doing this:

t.test(y~x)

when you mean to do this

t.test(y,x)

In general use the ~ then you have data like

y <- 1:10
x <- rep(letters[1:2], each = 5)

and the , when you have data like

y <- 1:5
x <- 6:10

I assume you’re doing something like:

y <- 1:10
x <- rep(1,10)
t.test(y~x) #instead of t.test(y,x)

because the error suggests you have no variation in the grouping factor x

Leave a Comment