Search code examples
rdatetimefor-looptime-seriesnested-tibble

Can not get the list of all dates from a list of tibbles


I have a list of tibbles or list columns, each tibble contain a column with dates and the other one temperatures. I want to get the date in the index located in a vector but what I tried it doesn't work for a reason that I can't see. This is my code and results:

datetr = as.POSIXct(vector())
for (i in seq_along(dts)){
    datetr=as.POSIXct(dts[[i]][[1]][[stagt[i]]])
}

[1] "2019-11-04 15:18:32 UTC"

Where dts is the list of tibbles and stagt is the vector that contains the indexes.

This for-loop save on datetr the one date-time and not 106 values as I expected. Trying to understand what can be wrong I tried to change manually the indexes and then it works, but I need a list.

as.POSIXct(dts[[1]][[1]][[46]])
as.POSIXct(dts[[2]][[1]][[36]])

> as.POSIXct(dts[[1]][[1]][[46]])
[1] "2018-08-07 18:30:31 UTC"
> as.POSIXct(dts[[2]][[1]][[36]])
[1] "2018-08-08 17:46:05 UTC"

Solution

  • Perhaps you could try this:

    datetr = as.POSIXct(vector())
    for (i in seq_along(dts)){
        datetr <- as.POSIXct(c(datetr, dts[[i]][[1]][[stagt[i]]]))
    }