Peter Dalgaard <[EMAIL PROTECTED]> writes: > "CENDOYA, Gabriela" <[EMAIL PROTECTED]> writes: > > > for (myname in names(myframe)){ > > mycall <- substitute(lm(myvar~etc.etc.....),list(myvar=as.name(myname))) > > myfit <- eval(mycall) > > print(summary(myfit)) > > } ## by Peter Dalgaard > > > > But instead of printing summary or Anova results, I need to generate a list > > containing all the lm() objects. > > Is that possible? How? > > Very easily: > > f <- function(myname){ > mycall <- substitute(lm(myvar~etc.etc.....),list(myvar=as.name(myname))) > myfit <- eval(mycall) > print(summary(myfit)) > } > > lapply(names(myframe),f)
Whoops. A bit too quick there: You want the lm objects, not summaries and no printing, so make that f <- function(myname){ mycall <- substitute(lm(myvar~etc.etc.....),list(myvar=as.name(myname))) eval(mycall) } lapply(names(myframe),f) Or, if you dont care about having the names substituted in the lm calls (the list elements will get named appropriately) lapply(myframe, function(y) lm(y~etc.etc.)) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help