-1

i working in time series data, i convert the data into functional data. I predict the result for one year in a list, know i want to extract the set of variables X1 to X23 and the first column of each variable fcst. which given below as:

           $`X1`
               fcst     lower     upper        CI
X1.fcst -0.07640791 -0.331303 0.1784872 0.2548951

$X2
               fcst      lower     upper        CI
X2.fcst -0.03330083 -0.2084294 0.1418278 0.1751286

$X3
               fcst     lower      upper        CI
X3.fcst -0.06458028 -0.168395 0.03923446 0.1038147

$X4
               fcst      lower      upper        CI
X4.fcst -0.03543038 -0.1489443 0.07808351 0.1135139

$X5
                fcst      lower     upper        CI
X5.fcst -0.008606664 -0.1190324 0.1018191 0.1104257

$X6
              fcst       lower     upper         CI
X6.fcst 0.07780536 0.004739952 0.1508708 0.07306541

$X7
                fcst       lower      upper         CI
X7.fcst 0.0001696339 -0.05762494 0.05796421 0.05779458

$X8
              fcst       lower      upper         CI
X8.fcst 0.01906647 -0.02560325 0.06373619 0.04466972

$X9
              fcst        lower      upper         CI
X9.fcst 0.02699226 -0.007552674 0.06153719 0.03454493

$X10
               fcst        lower      upper        CI
X10.fcst 0.01657228 -0.002895615 0.03604018 0.0194679

$X11
               fcst       lower     upper         CI
X11.fcst 0.01149996 -0.00464947 0.0276494 0.01614943

$X12
                fcst        lower      upper          CI
X12.fcst 0.002828719 -0.006073137 0.01173058 0.008901856

$X13
                fcst        lower       upper          CI
X13.fcst 0.001162544 -0.004830854 0.007155941 0.005993398

$X14
                  fcst        lower       upper          CI
X14.fcst -0.0007683052 -0.004022551 0.002485941 0.003254246

$X15
                fcst       lower       upper          CI
X15.fcst 0.001159246 -0.00112432 0.003442812 0.002283566

$X16
                 fcst        lower       upper          CI
X16.fcst 3.783031e-05 -0.001187894 0.001263555 0.001225725

$X17
                 fcst         lower       upper       CI
X17.fcst 0.0004083794 -0.0006906204 0.001507379 0.001099

$X18
                 fcst        lower        upper          CI
X18.fcst 0.0001902179 -0.000322076 0.0007025119 0.000512294

$X19
                 fcst        lower        upper           CI
X19.fcst -3.61172e-05 -0.000503531 0.0004312966 0.0004674138

$X20
                 fcst         lower        upper           CI
X20.fcst 7.827828e-05 -0.0002146661 0.0003712227 0.0002929444

$X21
                  fcst         lower        upper           CI
X21.fcst -7.967715e-05 -0.0002784039 0.0001190496 0.0001987268

$X22
                  fcst         lower        upper           CI
X22.fcst -9.333431e-05 -0.0002418255 5.515691e-05 0.0001484912

$X23
                 fcst         lower        upper           CI
X23.fcst 3.286971e-05 -0.0001001939 0.0001659333 0.0001330636


how i can i extract the set of variables and the first column of each variable. Can any one help me in this regard, i will be thanks.

  • Hi, For more detail guide you can refer this link. https://stackoverflow.com/questions/4227223/convert-a-list-to-a-data-frame – Tushar Lad Jan 16 '20 at 05:25

1 Answers1

0

Unless the list is massive, it is probably simpler just to convert it to a data frame and extract the rows and column you need:

df <- do.call(rbind, yourlist)
df[1:23, "fcst"]

Alternatively you can use sapply:

sapply(1:23, function(x) yourlist[[x]]$fcst)
dcarlson
  • 10,936
  • 2
  • 15
  • 18
  • thanks alot dcarlson of your value suggestion i have a list of length 8760 , how i can convert into data frame?please help.. – faheem jan Jan 16 '20 at 05:30
  • Use `do.call` to convert to a data frame as I illustrated above. – dcarlson Jan 16 '20 at 05:43
  • when i convert it into data frame the list it would merges the other result which is not require for example lower upper and cl i not need these results for further analysis. i only use only fcst for further analysis. i want to extract the variable x1 to x23 and their fcst values. – faheem jan Jan 16 '20 at 06:04
  • The two lines above do that. You don't need to save the data frame if you don't need it. How long did it take these two lines to run on your computer? I've added another approach using `sapply`. – dcarlson Jan 16 '20 at 18:33