0

My code is ttResults <- t.test(airline$favorite_count ~ airline$screen_name). It's for a data frame I have. The favorites is my numerical var and screen name is my categorical var. I've done the same test with similar code before and it worked.

I'm pretty new to R. I'm not sure how to check how many levels I have or recode to adjust the levels.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • Have you seen this? https://stackoverflow.com/questions/29421475/basic-t-test-grouping-factor-must-have-exactly-2-levels – Ronak Shah Apr 30 '21 at 01:06
  • You should do `t.test(favorite_count~screen_name, data=airline)`. Seems that the screen name does not have 2 categories. Hence you cannot do a t.test. probably you should consider an anova – Onyambu Apr 30 '21 at 01:06
  • 1
    What does `nlevels(airline$screen_name)` return? Or if it's not a factor, `length(unique(airline$screen_name))` will tell you the number of groups you have. A t-test only works with two groups so it doesn't sound like it's the right test for your data. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Apr 30 '21 at 01:15

0 Answers0