I have a variable out
that is a list of lists and I want to format the first child list to a dataframe. Say my out
looks like this:
[[1]]
[[1]]$id
[1] "1"
[[1]]$input
[1] "A" "B" "C"
[[2]]
[[2]]$id
[1] "2"
[[2]]$input
[1] "R" "S" "T"
class(out)
and class(out[[1]])
confirms that this is a list of lists.
I want to create a "long" dataframe that should look like this:
id input
1 "A"
1 "B"
1 "C"
2 "R"
2 "S"
2 "T"
I tried:
lapply(out, function(x){
as.data.frame(x)
})
but this seems to do an cbind
and creates new columns for each child list.
Any help is highly appreciated.