In order to use the for loop, I'm trying to replace the arguments in this function by variables:
lm(mpg~cylinders, data=Auto)
So I did this:
var1='cylinders'
lm((paste('mpg ~',var1)), data = Auto)
It worked fine.
Now, I wonder how we can replace the arguments cylinders+acceleration by var1 and var2.
So tried the same method. I tried to replace this:
lm(mpg~cylinders+acceleration, data=Auto)
by
var1='cylinders'
var2 = 'acceleration'
lm((paste('mpg ~',var1+var2)), data = Auto)
But I got a message error:
Error in var1 + var2 : non-numeric argument to binary operator
So I want to learn how I can work with var1 and var2 in order to use for loop afterwards.