简体   繁体   中英

lm function throws an error in terms.formula() in R

I am trying to run linear modelling on the training data frame, but it is not giving me the output.

It gives me an error saying

Error in terms.formula(formula, data = data) : 
'.' in formula and no 'data' argument

Code

n <- ncol(training) 
input <- as.data.frame(training[,-n])
fit <- lm(training[,n] ~.,data = training[,-n])

There's no need to remove the column from the data to perform this operation, and it's best to use names.

Say that your last column is called response . Then run this:

lm(response ~ ., data=training)

It's hard to say that this is the formula that you need. If you provide a reproducible example, that will become clear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM