I have a data frame df.
df <- data.frame(shop = c("A", "A", "A", "B", "B", "B", "C", "C", "C"),
product = c(1,2,3,4,5,1,5,2,4))
For every pair of shops i.e AB, AC and BC, I wish to count the number of common product.
The expected output is as follows
pair common_product
AB 1 # Because 1 is common
AC 1 # Because 2 is common
BC 2 # Because 5 and 4 is common