I have a huge file like this:
library(tidyverse)
test <- structure(list(one = c(5014, 5014, 5014, 5033, 5033, 5033, 5040,
5040, 5040, 5171, 5171, 5171, 5174, 5174, 5174, 5183, 5183, 5183,
5193, 5193, 5193, 5304, 5304, 5304), two = c(5033, 5040, 5304,
5014, 5040, 5304, 5014, 5033, 5304, 5174, 5183, 5331, 5171, 5183,
5331, 5171, 5174, 5331, 5161, 1538, 5190, 5014, 5033, 5040)), row.names = c(NA,
-24L), class = c("tbl_df", "tbl", "data.frame"))
The numbers in the two columns match to other ones in a (recursive?) way (sorry, I don't know how to explain it better). In this example example, it is obvious (for humans, not for computers) that there are only three groups. How can I separate these groups?
All I need is something like that:
group number
1 5014
1 5033
1 5040
1 5304
2 5171
2 5174
2 5183
2 5331
3 5193
3 5161
3 1538
3 5190
I guess it is possible with multiple self-joins, but this seems to be extremely tedious...