[R] List of lm objects

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Oct 23 22:24:52 CEST 2003


"CENDOYA, Gabriela" <gcendoya at balcarce.inta.gov.ar> 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)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list