The goal is to convert a nested list which sometimes contain missing records into a data frame. An example of the structure when there are missing records is:
You could create a list of data.frames:
dfs <- lapply(mylist, data.frame, stringsAsFactors = FALSE)
Then use one of these:
library(plyr)
rbind.fill(dfs)
or the faster
library(dplyr)
rbind_all(dfs)
In the case of dplyr::rbind_all
, I am surprised that it chooses to use ""
instead of NA
for missing data. If you remove stringsAsFactors = FALSE
, you will get NA
but at the cost of a warning... So suppressWarnings(rbind_all(lapply(mylist, data.frame)))
would be an ugly but fast solution.