-2

I'm using this dataset

> mtcars

make       . mpg cyl disp  hp drat   wt ...
Mazda RX8   21.0   6  160 110 3.90 2.62 ...
Mazda RX7   21.0   6  160 110 3.90 2.88 ...
Datsun 710  22.8   4  108  93 3.85 2.32 ...

Would like to do multiple regression like

lm(make ~ mpg + cal + disp + ....., data=mtcars)

There are over 50 variables in the dataframe. I have tried

lm(mtcars$make ~ mtcars[, make])

but didn't work.

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
Bruce Brown
  • 217
  • 2
  • 4
  • 8

1 Answers1

1

I'm not sure why you are trying to predict make from all the other factors. Make is the row.name and not a factor. But I think this code gives you what you are looking for, but to predict mpg instead of make.

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

The period stands for all other factors in the data frame.

Tedward
  • 1,652
  • 15
  • 19