0

New to this community and thanks in advance for any help. I am just getting started in using R for modeling and have run across the above error. This is for a simple formula using mtcars R dataset. Can anyone provide some suggestions to fix it? I ran across similar questions in the archives but couldn't find a solution.

LMfit1 <-train(mtcars$mpg ~ ., data =TrainData, method = "lm")
    
Error in terms.formula(formula, data = data) : 
 '.' in formula and no 'data' argument
Sinval
  • 1,315
  • 1
  • 16
  • 25
GaryK
  • 1

2 Answers2

0

Try LMfit1 <- lm(mtcars$mpg ~ ., data = TrainData)

Also, make sure you have TrainData defined somewhere.

If you can't get that to work, either use

lm(mtcars$mpg ~ ., data = mtcars)

or create a TrainData (here's an example)

Dharman
  • 30,962
  • 25
  • 85
  • 135
Rookie0101
  • 17
  • 3
0

Thanks for responding.
1.This didn't work.
LMfit1<- lm(mtcars$mpg ~ ., data= TrainData)

  1. This did work. LMfit1<- lm(mtcars$mpg ~., data=mtcars)

  2. I think the problem is in the TrainData set. I know that the TrainData is numeric; I tried converting to data.frame (as.data.frame) but didn't help. Here is the build:

DataSplit <- createDataPartition(y = car_dat$mpg, p=0.7, list= FALSE)

TrainData <- car_dat[DataSplit]

TestData <- car_dat[-DataSplit]

GaryK
  • 1