Dear R-ers,
I have a data frame data with predictors x1 through x5 and the
response variable y.
I am running a simple regression:

reg<-lm(y~x1, data=data)

I would like to loop through all predictors. Something like:
predictors<-c("x1","x2",... "x10)
for(i in predictors){
  reg<-lm(y~i)
 etc.
}

But it's not working. I am getting an error:
Error in model.frame.default(formula = Y ~ x1 + x2 + x3 + i, data = sample,  :
  variable lengths differ (found for 'i')

How can I make it take predictor names in the lm formula?
Thank you!

-- 
Dimitri Liakhovitski
Ninah.com
dimitri.liakhovit...@ninah.com

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to