R list of lists to data.frame

AS @dimitris_ps mentioned earlier, the answer could be:

do.call(rbind, listHolder)

Since do.call naturally "strips" 1 level of the "list of list", obtaining a list, not a list of lists.

After that, rbind can handle the elements on the list and create a matrix.


The value of nrow needs to be fixed. I fixed your code as follows:

dd  <-  as.data.frame(matrix(unlist(listHolder), nrow=length(unlist(listHolder[1]))))

This is the easiest solution I've found.

library(jsonlite)
library(purrr)
library(data.table)

dt_list <- map(list_of_lists, as.data.table)
dt <- rbindlist(dt_list, fill = TRUE, idcol = T)

dt

This achieves a similar result, but is more intuitive (to me at least)

#Generate fake data 
listoflists=list(c(1,'a',3,4),c(5,'b',6,7))

#Convert to a dataframe, transpose, and convert the resulting matrix back to a dataframe
df= as.data.frame(t(as.data.frame(listoflists)))

#Strip out the rownames if desired
rownames(df)<-NULL

#Show result
df