This answer partially consists of comments in the original question.
That is not an error. It's a warning message (it differs from error). It's generated because you attempt to use lm()
for a factor-type response variable. Operations like + and - does not work on factor, hence the message "-" not meaningful for factors.
If the response is truly a categorical variable, lm()
might not be the right way to go to model it. Alternatives in this situation:
glm()
: Binary logistic regression, Poisson regression, negative binomial regression
MASS::polr()
: Ordinal logistic regression
nnet::multinom()
: Multinomial logistic regression
- and many more others.
Please research the corresponding methods before actually using it.
If the response is actually NOT a categorical variable, you will want to look further why it is coded as a factor, and turn it to numeric first.