[R] Strange t-test error: "grouping factor must have exactly 2 levels" while it does...

Tymek W es_uomikim at op.pl
Fri Jul 10 00:04:16 CEST 2009


Hi,

Could anyone tell me what is wrong:

> length(unique(mydata$myvariable))
[1] 2
>

and in t-test:

(...)
Error in t.test.formula(othervariable ~ myvariable, mydata) :
  grouping factor must have exactly 2 levels
>

I re-checked the code and still don't get what is wrong.

Moreover, there is some strange behavior:

/1 It seems that the error is vulnerable to NA'a, because it affects
some variables in data set with NA's and doesn't affect same ones in
dataset with NA's removed.

/2 It seems it works differently with different ways of using
variables in t.test:

eg. it hapends here: t.test(x~y, dataset) and does not here:
t.test(dataset[['x']]~dataset[['y']])

Does anyone have any ideas?

Greetz,
Timo




More information about the R-help mailing list