3

I have troubles with converting a list containing dates into a date.frame, as the dates are converted into integers when using the unlist command.

The list I work on looks similar to this, just with way more data frames:

list(
    data.frame(
        date = as.POSIXct(Sys.time() + days(seq(0, 4))),
        value = c(4,5,1,7,9)),
    data.frame(
        date = as.POSIXct(Sys.time() + days(seq(5, 9))),
        value = c(3,3,5,1,7))
)

What I am looking for a method to convert it into a single data.frame that look like this:

                  date   value
1  2017-07-24 14:30:18       4
2  2017-07-25 14:30:18       5
3  2017-07-26 14:30:18       1
4  2017-07-27 14:30:18       7
5  2017-07-28 14:30:18       9
6  2017-07-29 14:30:18       3
7  2017-07-30 14:30:18       3
8  2017-07-31 14:30:18       5
9  2017-08-01 14:30:18       1
10 2017-08-02 14:30:18       7
Christoffer
  • 643
  • 1
  • 6
  • 22

1 Answers1

8

We can use bind_rows

library(dplyr)
bind_rows(lst)

Or with base R

do.call(rbind, lst)

Or using data.table

library(data.table)
rbindlist(lst)
akrun
  • 874,273
  • 37
  • 540
  • 662