1

我希望cbind lm summary存储在不同的列表中。我有 20 种不同的模型存储,所以我想cbind手动 avoir。

你知道我该怎么做吗?

这是我的一个样本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    ***
4

2 回答 2

4

尝试这个:

 data<- as.data.frame(data)
于 2015-07-01T11:55:20.253 回答
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可能并不总是以所需格式产生输出的事实。在此处查看有关此问题的更多讨论并在相应评论中链接。

于 2015-07-01T13:06:46.270 回答