I have a linked list like data,
d <- data.frame(prev=c(NA, "a", "c", "b", "e", "f", NA),
`next`=c("a", "b", "d", "c", "f", "g", "e")
,stringsAsFactors = FALSE)
# > d
# prev next.
# 1 <NA> a
# 2 a b
# 3 c d
# 4 b c
# 5 e f
# 6 f g
# 7 <NA> e
if the column "prev" is NA, the column "next" is the head node. And I want to extract the linked list nodes like this:
list(c("a", "b", "c", "d"),
c("e", "f", "g"))
I try to use while loop to do it, which I think it is not a good idea. What I want to do is using base r and vectorising function to do it.