我有许多线性模型的摘要对象列表。每个摘要对象obj都有一个obj $ aliased成分,其中包含由于秩不足而从统计模型中省略的系数。对于列表中的每个模型,我想对别名向量中的值求和并返回值列表。
下面是该问题的一个最小工作示例,但代码引发了错误。即使当我深入到列表中的每个模型摘要对象时,它看起来也无法实际访问$ alised之类的组件。欢迎提供建议。
# example data
dat <- data.frame(x = rnorm(5),
y = runif(5))
# store models in list (actual case has many models)
foo <- summary(with(dat, lm(y~x)))
foo$aliased # this is what i want to pull for each object
sum(foo$alised) # this is what I want to return for each element in the list
bar <- list(foo)
# try to sum the logical vector "aliased" in each element of the list, doesn't work
lapply(bar, FUN = function(x){ sum(x[[1]]$aliased) })