r滤波器和汇总结果来自lapply模型摘要
我正在尝试使用dlply在数据集的子集上执行的多个回归模型过滤和汇总结果。
这就是我的模型的方式:
library(plyr)
data("mtcars")
models = dlply(mtcars, .(cyl), function(df) lm(mpg ~ hp,data=df))
lapply(models, summary)
现在,我将类似不同模型的结果(圆柱体4、6、8)结合在一起:
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,])
)
是否有一种方法可以更有效地总结这一点?
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)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:
4`)[2,]),
c("Cylinder 6", coef(lapply(models, summary)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:
6`)[2,]),
c("Cylinder 8", coef(lapply(models, summary)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:
8`)[2,])
)
Is there a way to summarize this more efficiently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以从
broom
中使用整理
,而不是使用摘要
和coef
。我们还可以将模型数据直接输送到map2_df
。输出
We can use
tidy
frombroom
, rather than usingsummary
andcoef
. We can also just pipe the model data straight intomap2_df
.Output