identify groups of linked episodes which chain together
问题 Take this simple data frame of linked ids: test <- data.frame(id1=c(10,10,1,1,24,8),id2=c(1,36,24,45,300,11)) > test id1 id2 1 10 1 2 10 36 3 1 24 4 1 45 5 24 300 6 8 11 I now want to group together all the ids which link. By \'link\', I mean follow through the chain of links so that all ids in one group are labelled together. A kind of branching structure. i.e: Group 1 10 --> 1, 1 --> (24,45) 24 --> 300 300 --> NULL 45 --> NULL 10 --> 36, 36 --> NULL, Final group members: 10,1,24,36,45,300