是否有一個函數可以從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