On Wed, Jul 28, 2010 at 8:59 AM, Joshua Wiley <jwiley.ps...@gmail.com> wrote: > Hi Tony, > > I am sure there are other ways, but I would create formula objects and > then pass them to lm(). Here's an example: > > mydata <- data.frame(Y = 1:10, X1 = 11:20, X2 = 21:30) > > my.names <- names(mydata)[-1] > > for(i in my.names) { > my.formula <- formula(paste("Y ~ ", i, sep = "")) > my.lm <- lm(my.formula, data = mydata) > print(summary(my.lm)) > } >
You might want to also replace the my.lm<- line above with: my.lm <- do.call("lm", list(my.formula, data = quote(mydata))) so that the Call: line in the output comes out fully expanded. ______________________________________________ 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.