I am trying to convert a list of 13,000 elements, each element being a zoo object with nr = 230 and ncol = 4, to a dataframe.
I have tried setattr(mylist, 'class', 'data.frame'), but it resulted in a huge vector of NAs.
I have also tried the quickdf(mylist) function from the plyr package, but that didn't work either.
The do.call(rbind.data.frame, mylist)type methods are very slow, thus not an option in this case.
Any suggestion as to the most efficient method to convert such a list to a dataframe?
Use rbindlist from the data.table package.
data <- matrix(data = 1, nrow = 230, ncol = 4)
lstData <- rep(list(data), 16000)
library(data.table)
lstData <- Map(as.data.frame, lstData)
dfrData <- rbindlist(lstData)
system.time(dfrData <- rbindlist(lstData))
user system elapsed
0.12 0.03 0.15
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With