I have a nested lists like this :
x <- list(x = list(a = 1,
b = 2),
y = list(a = 3,
b = 4))
And I would like to convert the nested list into data.frames and then bind all data frames into one.
For this level of nesting I can do it with this line :
do.call(rbind.data.frame, lapply(x, as.data.frame, stringsAsFactors = FALSE))
So the result is :
a b
x 1 2
y 3 4
My problem is that I would like to achieve that regardless of the level of nesting. Another example with this list :
x <- list(X = list(x = list(a = 1,
b = 2),
y = list(a = 3,
b = 4)),
Y = list(x = list(a = 1,
b = 2),
y = list(a = 3,
b = 4)))
do.call(rbind.data.frame, lapply(x, function(x) do.call(rbind.data.frame, lapply(x, as.data.frame, stringsAsFactors = FALSE))))
a b
X.x 1 2
X.y 3 4
Y.x 1 2
Y.y 3 4
Does anyone has an idea to generelized this to any level of nesting ? Thanks for any help