Re: [R] looping through predictors

2010-03-09 Thread Dimitri Liakhovitski
Thank you very much- I found ?as.formula of great help! Dimitri On Tue, Mar 9, 2010 at 6:36 PM, David Winsemius wrote: > I already answered a very similar question earlier today. It was in the > context of a question about a different regression function, but the formula > methods are generic.

Re: [R] looping through predictors

2010-03-09 Thread David Winsemius
I already answered a very similar question earlier today. It was in the context of a question about a different regression function, but the formula methods are generic. Look for "Question on passing in parameter to Cox hazard". (That does not mean I approve of such fishing expeditions.) -

Re: [R] looping through predictors

2010-03-09 Thread Phil Spector
Dimitri - Without commenting on the wiseness of such an approach, here's one way to do what you want: regs = lapply(predictors,function(var)lm(data$y~data[,var])) names(regs) = predictors Now regs[['x1']] holds the lm output from the regression of y on x1, regs[['x2']] holds the lm output fr

[R] looping through predictors

2010-03-09 Thread Dimitri Liakhovitski
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. } B