I have three text documents stored as a list of lists called \"dlist\":
dlist <- structure(list(name = c(\"a\", \"b\", \"c\"), text = list(c(\"the\", \"quick\
If you convert your dlist
to a named list (a better suited structure in my opinion), you can use stack()
to get the two column data.frame you want.
(The rev()
and setNames()
calls in the second line are just one of many ways to adjust the column ordering and names to match the desired output shown in your question.)
x <- setNames(dlist$text, dlist$name)
setNames(rev(stack(x)), c("name", "text"))
# name text
# 1 a the
# 2 a quick
# 3 a brown
# 4 b fox
# 5 b jumps
# 6 b over
# 7 b the
# 8 c lazy
# 9 c dog