Error in wilcox.test.formula(donnee$Shan ~ donnee$AnnÃ.e) : grouping factor must have exactly 2 levels

Hi, this is my first topic, sorry if it is not clear or that I did not choose the right category.
To explain the context, I am currently analyzing whether my species richness for 3 different years is significant. Here are the lines of code:

shapiro.test(donnee$RS) (pvalue>0,05)

But Rstudio answers me:
Error in t.test.formula(donnee$RS ~ donnee$AnnÃ.e) :
grouping factor must have exactly 2 levels

This is not the first time this has happened to me, and I can't find a solution on the internet.
I tried swapping the 2 variables, or putting a point instead of the ~.
But no results...

Can someone answer me and explain to me what is wrong?

Thanks a lot !
Happy Easter.


How many levels does donnee$AnnÃ.e have? To show the answer to that, run

NewDF <- donnee[ , c("RS", "AnnÃ.e")]

If that shows that AnnÃ.e has the Class character, then run

NewDF$AnnÃ.e <- factor(DF$AnnÃ.e)

Does one of those show that AnnÃ.e has something other than two levels?

Hi! Thanks for your answers.
Indeed, my AnnÂ.e category has 3 levels (2015,2018,2022).
If I have more than two levels, I can't use the student test?

Yes, a student t test requires exactly two levels. You can do an ANOVA test for more levels. The aov() function will do that.

Ho ok, thanks !

Great week

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.