R-Studio - Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels

rstudio

#1

Hi,

I am running into an issue with R-Studio where when I attempt to run regression of a subset of the full data frame I get the following error:

Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels

I understand this may mean that one or more variables have one level. But, the issue is all my variables are numerical and should not have this error. Is there anything I can do to write something within the code that will skip over these errors and proceed with the data that does work?

Thank you


#2

Welcome to community!

Could you update your title so that it is more descriptive and informative? From our Writing r coding questions guide;

Write now it reads like you are suggesting there is an issue with how RStudio runs a regression. I'd suggest summarizing what you are doing and the error you get.


Also, with a question like this, it's polite to pose your questions as a reproducible example, or reprex for short. (FAQ: What's a reproducible example (`reprex`) and how do I do one? I'd particularly like to see a minimal snippet of data that produces this error). That'll make it much easier to help diagnose the issue here.