[R] Forcing results from lm into datframe

Hadley Wickham hadley at rice.edu
Tue Oct 26 21:18:11 CEST 2010


On Tue, Oct 26, 2010 at 11:55 AM, Dennis Murphy <djmuser at gmail.com> wrote:
> Hi:
>
> When it comes to split, apply, combine, think plyr.
>
> library(plyr)
> ldply(split(afvtprelvefs, afvtprelvefs$basestudy),
>         function(x) coef(lm (ef ~ quartile, data=x, weights=1/ef_std)))

Or do it in two steps:

models <- dlply(aftvprelvef, "basestudy", function(x)
  lm(ef ~ quartile, data=x, weights=1/ef_std)
coefs <- ldply(models, coefs)

That way you can easily pull out other info

rsq <- function(x) summary(x)$r.squared
ldply(models, rsq)

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list