“摘要"多个LM和GLM对象 [英] `Summary` multiple LM and GLM objects

查看:163
本文介绍了“摘要"多个LM和GLM对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在R中有50个lmglm对象.我想获取所有这些对象的摘要,而不必键入50次.有快速的方法吗?数据集的名称以相同的方式开头: lin.mod.t# lin.mod.s#,其中{#= 1,2,...,25 }.我可以使用

I have 50 lm and glm objects in R. I want to get the summary of all of them without having to type summary(lm...) 50 times. Is there a quick way to do it? The names of the dataset begin the same way: lin.mod.t# or lin.mod.s# where {# = 1,2,...,25}. I can list all the models using

ls(pattern = "lin.mod")
objects(pattern = "lin.mod")

但是对于使用lsobjects的结果,我无法运行summary.我使用了summary(eval(parse(text = ls(pattern = "lin.mod")))),但这仅运行第一个.有什么建议?也许使用lapply?

But I cannot run summary for the outcomes of using ls or objects. I used summary(eval(parse(text = ls(pattern = "lin.mod")))), but this only runs the first one. Any suggestions? Maybe use lapply?

推荐答案

如何?

# 2 sample models
lin.mod.1 <- lm(mpg ~ wt, data = mtcars);
lin.mod.2 <- lm(mpg ~ wt, data = mtcars);

# Get models and store in list
lst <- lapply(ls(pattern = "lin.mod"), get);

# Summary of models
res <- lapply(lst, summary);

说明:get与当前环境中的模式"lin.mod"匹配并存储在列表lst中的所有模型.使用lapply将所有模型的summary存储在列表res中.

Explanation: get all models that match pattern "lin.mod" from the current environment and store in list lst. Use lapply to store summary of all models in list res.

这篇关于“摘要"多个LM和GLM对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆