是否有一个函数可以从coeftest
对象中提取两个或多个列?一次只能容纳一个coeftest
对象,但是我可以对列表执行相同操作(除了for()
循环外)吗?从coeftest对象列表中提取列
> # meaningless data
> temp <- data.frame(a = rnorm(100, mean = 5), b = rnorm(100, mean = 1),
+ c = 1:100)
> formulas <- list(a ~ b, a ~ c)
> models <- lapply(formulas, lm, data = temp)
> library(lmtest)
> cts <- lapply(models, coeftest)
> # easy to extract columns one object at a time
> cts[[1]][, 1:2]
Estimate Std. Error
(Intercept) 5.0314196 0.1333705
b -0.1039264 0.0987044
> # but more difficult algorithmically
> # either one column
> lapply(cts, "[[", 1)
[[1]]
[1] 5.03142
[[2]]
[1] 5.312007
> # or two
> lapply(cts, "[[", 1:2)
Error in FUN(X[[1L]], ...) : attempt to select more than one element
也许更根本的问题是,如果有一种方法打开coeftest
对象的肉到数据帧,这将让我单独提取柱,然后用mapply()
。谢谢!
编辑:我想结束与第一和第二列的矩阵(或数据帧)。
[[1]]
Estimate Std. Error
(Intercept) 5.0314196 0.1333705
b -0.1039264 0.0987044
[[2]]
Estimate Std. Error
(Intercept) 5.312007153 0.199485363
c -0.007378529 0.003429477
如果您提供期望的结果,可能会更容易回答。 – kohske 2011-06-15 15:11:11
@kohske - 好的电话。谢谢。 – 2011-06-15 15:53:58