从列表中提取特定元素

时间:2020-08-23 19:22:58

标签: r

我的结果是列表形式的,

$X1
             fcst      lower     upper        CI
X1.fcst 0.1217507 -0.1295139 0.3730153 0.2512646

$X2
              fcst      lower     upper        CI
X2.fcst 0.03534357 -0.1204348 0.1911219 0.1557783

$X3
              fcst       lower     upper         CI
X3.fcst 0.03301191 -0.05692609 0.1229499 0.08993801

$X4
               fcst       lower      upper         CI
X4.fcst 0.001622621 -0.06784667 0.07109191 0.06946929

$X5
               fcst       lower     upper         CI
X5.fcst 0.002349806 -0.05053648 0.0552361 0.05288629

$X6
                fcst       lower      upper         CI
X6.fcst -0.004397929 -0.04704999 0.03825413 0.04265206

$X7
               fcst       lower      upper        CI
X7.fcst 0.003693691 -0.02470371 0.03209109 0.0283974

$X8
                fcst       lower     upper         CI
X8.fcst -0.008413914 -0.03223563 0.0154078 0.02382171

$X9
                fcst       lower      upper        CI
X9.fcst -0.001122924 -0.02466012 0.02241428 0.0235372

我想提取 fcst 进行进一步分析,我尝试以这种方式解决

ad1 <- head(sapply(unlist(pred.ff1, recursive = FALSE), `[`, 1), 'fcst')

它以这种形式给出结果

 X11           X12           X13           X14           X21           X22 
 1.217507e-01 -1.295139e-01  3.730153e-01  2.512646e-01  3.534357e-02 -1.204348e-01 
          X23           X24           X31           X32           X33           X34 
 1.911219e-01  1.557783e-01  3.301191e-02 -5.692609e-02  1.229499e-01  8.993801e-02 
          X41           X42           X43           X44           X51           X52 
 1.622621e-03 -6.784667e-02  7.109191e-02  6.946929e-02  2.349806e-03 -5.053648e-02 
          X53           X54           X61           X62           X63           X64 
 5.523610e-02  5.288629e-02 -4.397929e-03 -4.704999e-02  3.825413e-02  4.265206e-02 
          X71           X72           X73           X74           X81           X82 
 3.693691e-03 -2.470371e-02  3.209109e-02  2.839740e-02 -8.413914e-03 -3.223563e-02 
          X83           X84           X91           X92           X93           X94 
 1.540780e-02  2.382171e-02 -1.122924e-03 -2.466012e-02  2.241428e-02  2.353720e-02 
         X101          X102          X103          X104          X111          X112 
 1.777253e-03 -9.831355e-03  1.338586e-02  1.160861e-02 -8.050355e-04 -1.230450e-02 
         X113          X114          X121          X122          X123          X124 
 1.069443e-02  1.149946e-02  1.545022e-04 -4.632798e-03  4.941803e-03  4.787300e-03 
                        

它不能从列表中提取特定元素。可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

如果您的列表名为LIST

FCST = lapply(LIST, function(n){
         n$fcst
       })%>% unlist

要使用%>%,请安装“ magrittr”库。