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:
Or...
library(dplyr)
df1 %>%
left_join(df1, by = "place") %>%
filter(id.x < id.y) %>%
group_by(id.x, id.y) %>%
summarise(count = n())
EDIT:
If IDs are factors operator <
won't work. Conversion adds another line to the solution (credits to Steven Beaupré):
df1 %>%
left_join(df1, by = "place") %>%
mutate_each(funs(as.character(.))) %>%
filter(id.x < id.y) %>%
group_by(id.x, id.y) %>%
summarise(count = n())