I have this list in R:
my_list = list("word",c("word", "word"), "word", c("word", "word","word"), "word")
[[1]]
[1] "word"
[[2]]
[1] "word" "word"
[[3]]
[1] "word"
[[4]]
[1] "word" "word" "word"
[[5]]
[1] "word"
I would like to convert this list into a data frame that looks something like this:
col1 col2 col3
1 word
2 word word
3 word
4 word word word
5 word
# source code of the desired output
structure(list(col1 = c("word", "word", "word", "word", "word"
), col2 = c("", "word", "", "word", ""), col3 = c("", "", "",
"word", "")), class = "data.frame", row.names = c(NA, -5L))
I tried to use the answer provided here (How to split a column of list into several columns using R) for my question:
z = my_list
x <- do.call(rbind, z)
colnames(x) <- LETTERS[1:ncol(x)]
h = data.frame(cbind(z[c("sg", "time")], x))
But this is not giving me the desired output.
Can someone please show me how to do this?
Thank you!