lm -regression issues with Code

Dear "R" experts / helpers,
I'm still new with "R" and will appreciate your help to solve the following issue with a lineal regression error.
Your help will be very much appreciated!

r Code#
library(ggplot2)
library(caTools)
library(caret)
wines<-(wines_SPA)

split_index <- sample.split(wines$price,SplitRatio = 0.65)
View(split_index)

train<- subset(wines,split_index==T)
test <- subset(wines,split_index==F)

View(train)
View(test)

Error

mreg<- lm(price~.,data = train, drop.unused.levels=TRUE)
Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels

Any idea what I am missing here?

Hard to tell what, exactly, without a full reprex. See the FAQ: How to do a minimal reproducible example reprex for beginners

Use

str(train)

to see which variables are factors and to check that they all have at least two levels. If some are missing a level run the model with express arguments excluding those, rather than using the catch-all .

lm(price ~ fee + fi + fo + fum, data = train ...

This topic was automatically closed 21 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.