I have a list of ids and places where these ids have been. Now I want to find pairs of ids that have most places in common.
My data frame looks like this:
For a dplyr-esque solution,
dplyr
You could do:
left_join(df, df, by = "place") %>% rename(pair1 = id.x, pair2 = id.y) %>% filter(!pair1 == pair2, !duplicated(t(apply(., 1, sort))) == TRUE) %>% count(pair1, pair2)