-3

我有一个长度为 48 的列表,每个列表都有 3 个子列表。我想将列表折叠成一个数据框。该列表具有相同的结构。我想要的是一个 144 行 8 列的数据框。由于整个列表的 dput 很大,我从第一个列表中提供了可重现的数据。我已经在这个论坛和其他论坛上阅读了与这个问题相关的几个主题,但无法实现我想要的。

structure(list(o3t_01 = structure(list(Estimate = c(0.0146804140443251, 
-0.0201958312285972, 0.0152544121491188, -0.0113742189912915, 
0.00718202744126435, 0.00231054990362507, -0.000778914130262384
), Std..Error = c(0.00537496199305938, 0.00820059032995221, 0.00969113952126315, 
0.0101675826917485, 0.00966265981592954, 0.00817588949286964, 
0.00494131276612218), t.value = c(2.73125913509373, -2.46272895194301, 
1.57405763436275, -1.11867484495821, 0.743276445417678, 0.282605324550943, 
-0.15763303541574), Pr...t.. = c(0.00632633618260484, 0.0138141937219211, 
0.115522871591417, 0.263320285875607, 0.457341235198664, 0.777488410968677, 
0.874750874612085), est = c(1.0147887005707, 0.980006738590311, 
1.01537135456674, 0.988690222880809, 1.00720788005468, 1.00231322128111, 
0.999221389144602), lcl = c(1.00415409296128, 0.964380851449288, 
0.996266764602839, 0.969182175580195, 0.988312055161281, 0.986379417626981, 
0.989590668860169), ucl = c(1.02553593519604, 0.995885812372875, 
1.03484229757047, 1.00859093517163, 1.02646497970592, 1.01850441686206, 
1.00894583583139)), .Names = c("Estimate", "Std..Error", "t.value", 
"Pr...t..", "est", "lcl", "ucl"), row.names = c("Lag(envdf[, j], 0:6)Lag.0", 
"Lag(envdf[, j], 0:6)Lag.1", "Lag(envdf[, j], 0:6)Lag.2", "Lag(envdf[, j], 0:6)Lag.3", 
"Lag(envdf[, j], 0:6)Lag.4", "Lag(envdf[, j], 0:6)Lag.5", "Lag(envdf[, j], 0:6)Lag.6"
), class = "data.frame"), no2_01 = structure(list(Estimate = c(-0.00941253944647909, 
0.0195807638842728, -0.0146100995051316, 0.0075643006687482, 
-0.00266881777443428, 0.00437679373079139, -0.00360614850040052
), Std..Error = c(0.00401277445276284, 0.00604072704553612, 0.00717110222961073, 
0.00758944959720478, 0.00732918329130132, 0.00633302241352368, 
0.00430370436770732), t.value = c(-2.34564378269465, 3.2414581451321, 
-2.03735758288369, 0.996686330393993, -0.364135766341357, 0.691106622557515, 
-0.837917336390277), Pr...t.. = c(0.0190283395217023, 0.00119603466785681, 
0.0416603076321423, 0.318959087356011, 0.715770133776307, 0.48952667759945, 
0.402112258019656), est = c(0.990631619843975, 1.01977372442192, 
0.985496110125086, 1.00759298226418, 0.997334740353687, 1.00438638588166, 
0.996400345844234), lcl = c(0.98287082406448, 1.00777097740113, 
0.971741496617007, 0.992715639957524, 0.983110241580052, 0.991996271572576, 
0.988030798587111), ucl = c(0.998453695244001, 1.0319194264784, 
0.999445414704211, 1.02269328400171, 1.01176505161589, 1.01693125372862, 
1.00484079101404)), .Names = c("Estimate", "Std..Error", "t.value", 
"Pr...t..", "est", "lcl", "ucl"), row.names = c("Lag(envdf[, j], 0:6)Lag.0", 
"Lag(envdf[, j], 0:6)Lag.1", "Lag(envdf[, j], 0:6)Lag.2", "Lag(envdf[, j], 0:6)Lag.3", 
"Lag(envdf[, j], 0:6)Lag.4", "Lag(envdf[, j], 0:6)Lag.5", "Lag(envdf[, j], 0:6)Lag.6"
), class = "data.frame"), nox_01 = structure(list(Estimate = c(-0.0169508400123905, 
0.0272137400364233, -0.0161797457366529, 0.0138632271177889, 
-0.000376071378887284, 0.00271648961757436, -0.0126119087641059
), Std..Error = c(0.0102487910576239, 0.0158366987341556, 0.0186455284690967, 
0.0195354507975784, 0.0186352056244248, 0.0158059256879111, 0.0100012652992334
), t.value = c(-1.65393556343225, 1.71839728047174, -0.8677547414904, 
0.709644597477495, -0.0201806938150645, 0.171865265673874, -1.26103131821457
), Pr...t.. = c(0.0981946737012065, 0.0857774985348616, 0.385564481449501, 
0.477953059251017, 0.983899922439724, 0.863549445088588, 0.20734824148301
), est = c(0.983192017154268, 1.02758741586429, 0.983950443262082, 
1.01395976725426, 0.99962399932709, 1.00272018261874, 0.98746728806654
), lcl = c(0.963639062973523, 0.996181121053652, 0.948640870365264, 
0.975869650361809, 0.963771472301844, 0.972132541032585, 0.968298967419034
), ucl = c(1.00314171533584, 1.05998384724035, 1.02057428162764, 
1.05353661652367, 1.03681024884884, 1.03427024833773, 1.00701506230101
)), .Names = c("Estimate", "Std..Error", "t.value", "Pr...t..", 
"est", "lcl", "ucl"), row.names = c("Lag(envdf[, j], 0:6)Lag.0", 
"Lag(envdf[, j], 0:6)Lag.1", "Lag(envdf[, j], 0:6)Lag.2", "Lag(envdf[, j], 0:6)Lag.3", 
"Lag(envdf[, j], 0:6)Lag.4", "Lag(envdf[, j], 0:6)Lag.5", "Lag(envdf[, j], 0:6)Lag.6"
), class = "data.frame")), .Names = c("o3t_01", "no2_01", "nox_01"
))
4

2 回答 2

4

我采用了您的三个列表结构并将其嵌入为三个副本,以尝试理解您所描述的内容,然后做了两个do.call(rbind,... -操作:

bdat<- list(dat,dat,dat)
str( do.call( rbind, do.call( rbind, bdat) ) )
'data.frame':   63 obs. of  7 variables:
 $ Estimate  : num  0.01468 -0.0202 0.01525 -0.01137 0.00718 ...
 $ Std..Error: num  0.00537 0.0082 0.00969 0.01017 0.00966 ...
 $ t.value   : num  2.731 -2.463 1.574 -1.119 0.743 ...
 $ Pr...t..  : num  0.00633 0.01381 0.11552 0.26332 0.45734 ...
 $ est       : num  1.015 0.98 1.015 0.989 1.007 ...
 $ lcl       : num  1.004 0.964 0.996 0.969 0.988 ...
 $ ucl       : num  1.026 0.996 1.035 1.009 1.026 ...

这很容易转换为数据框。

于 2013-11-08T22:41:37.623 回答
2

两种选择:

do.call(rbind, Data) # alternative 1. Using R base

library(plyr)
ldply(Data)          # alternative 2. Using plyr package

使用@agstudy 数据,您还可以使用以下内容:

ll.new <- unlist(ll, recursive=FALSE)
do.call(rbind, ll.new)  # output is a matrix
ldply(ll.new)           # output is a dataframe
于 2013-11-08T21:21:31.230 回答