I am trying to filter and aggregate results from multiple regression models executed on a subset of dataset using dlply.
This is how I ran my models:
library(plyr)
data("mtcars")
models = dlply(mtcars, .(cyl), function(df) lm(mpg ~ hp,data=df))
lapply(models, summary)
Right now I am combining the results from different models(cylinder 4, 6, 8) like this:
rbind(
c("Cylinder 4", coef(lapply(models, summary)$`4`)[2,]),
c("Cylinder 6", coef(lapply(models, summary)$`6`)[2,]),
c("Cylinder 8", coef(lapply(models, summary)$`8`)[2,])
)
Is there a way to summarize this more efficiently?