I have the following data in R:
list0 <- list(ff = 45,gg = 23)
list1 <- list(a = 2, b=list0)
LIST <- list(mylist = list1)
I want to convert this list to a dataframe and get an output dataframe as follows, which has the following column header naming conventions:
a b.ff b.gg
1 2 45 23
any help is appreciated.
The LIST step was unnecessary:
> data.frame(list1)
a b.ff b.gg
1 2 45 23
vec <- unlist(LIST)
names(vec) <- sub("mylist.", "", names(vec))
dt <- data.frame(as.list(vec))
dt
a b.ff b.gg
1 2 45 23
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