簡體   English   中英

R-綁定列表(lm摘要)

[英]R - cbind lists ( lm summary )

我想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    ***

嘗試這個:

 data<- as.data.frame(data)

如果您想使用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可能並不總是以所需格式產生輸出的事實。 請在此處查看有關此問題的更多討論,並鏈接相應的評論。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM