Consider this nested list of dataframes:
df <- data.frame(x = 1:5, y = letters[1:5])
l <- list(df, list(df, df), list(df, list(df, df, list(df))), list(df), df)
How can one get from this deeply nested list to a simple list of dataframes:
list(df, df, df, df, df, df, df, df, df)
Usual solutions (like here) fails to keep dataframes’ structure.
>Solution :
A convenient option is to use rrapply:
rrapply(l, classes = "data.frame", how = "flatten")
Check whether it’s the same as the desired output:
identical(list(df, df, df, df, df, df, df, df, df),
rrapply(l, classes = "data.frame", how = "flatten"))
[1] TRUE