我期待存储在不同列表中的cbind
lm summary
。
我已经存储了20种不同的模型,所以我想亲自动手cbind
。
你知道我怎么能这样做吗?
以下是我的list
data = list(structure(list(`a alone` = structure(c(4L, 5L, 1L, 2L, 3L
), .Names = c("(Intercept)", "isexMALE", "numchild_rec1", "numchild_rec2",
"numchild_rec>2"), .Label = c("-59.819", "-61.193", "-72.312",
"126.679", "9.825"), class = "factor"), pvalue = structure(c(2L,
1L, 2L, 2L, 2L), .Names = c("(Intercept)", "isexMALE", "numchild_rec1",
"numchild_rec2", "numchild_rec>2"), .Label = c(" ", "***"), class = "factor")), .Names = c("a alone",
"pvalue"), row.names = c("(Intercept)", "isexMALE", "numchild_rec1",
"numchild_rec2", "numchild_rec>2"), class = "data.frame"), structure(list(
`b partner` = structure(c(4L, 5L, 1L, 2L, 3L), .Names = c("(Intercept)",
"isexMALE", "numchild_rec1", "numchild_rec2", "numchild_rec>2"
), .Label = c("-222.064", "-259.233", "-277.213", "365.149",
"8.608"), class = "factor"), pvalue = structure(c(2L, 1L,
2L, 2L, 2L), .Names = c("(Intercept)", "isexMALE", "numchild_rec1",
"numchild_rec2", "numchild_rec>2"), .Label = c(" ", "***"
), class = "factor")), .Names = c("b partner", "pvalue"), row.names = c("(Intercept)",
"isexMALE", "numchild_rec1", "numchild_rec2", "numchild_rec>2"
), class = "data.frame"), structure(list(`c child` = structure(c(4L,
1L, 5L, 2L, 3L), .Names = c("(Intercept)", "isexMALE", "numchild_rec1",
"numchild_rec2", "numchild_rec>2"), .Label = c("-36.267", "112.03",
"119.228", "23.706", "86.989"), class = "factor"), pvalue = structure(c(1L,
2L, 2L, 2L, 2L), .Names = c("(Intercept)", "isexMALE", "numchild_rec1",
"numchild_rec2", "numchild_rec>2"), .Label = c("**", "***"), class = "factor")), .Names = c("c child",
"pvalue"), row.names = c("(Intercept)", "isexMALE", "numchild_rec1",
"numchild_rec2", "numchild_rec>2"), class = "data.frame"))
我想得到像这样的输出
a alone pvalue b partner pvalue c child pvalue
(Intercept) 126.679 *** 365.149 *** 23.706 **
isexMALE 9.825 8.608 -36.267 ***
numchild_rec1 -59.819 *** -222.064 *** 86.989 ***
numchild_rec2 -61.193 *** -259.233 *** 112.03 ***
numchild_rec>2 -72.312 *** -277.213 *** 119.228 ***
答案 0 :(得分:4)
试试这个:
data<- as.data.frame(data)
答案 1 :(得分:1)
如果您想使用cbind
,可以执行以下操作:
data <- do.call(cbind, data)
此解决方案与接受的答案之间的输出存在细微差别,即cbind
将保留变量名称,而data.frame
将更改它们(以避免重复的列名称和也消除空间)。所以:
data_cb <- do.call(cbind, data)
data_df <- data.frame(data)
names(data_cb)
[1] "a alone" "pvalue" "b partner" "pvalue" "c child" "pvalue"
names(data_df)
[1] "a.alone" "pvalue" "b.partner" "pvalue.1" "c.child" "pvalue.2"
这表明cbind
可能并不总是以所需格式生成输出。请参阅有关此问题here的更多讨论,并在相应的评论中进行链接。