Count unique values of a column by pairwise combinations of another column in R
问题 Let's say I have the following data frame: ID Code 1 1 A 2 1 B 3 1 C 4 2 B 5 2 C 6 2 D 7 3 C 8 3 A 9 3 D 10 3 B 11 4 D 12 4 B I would like to get the count of unique values of the column "ID" by pairwise combinations of the column "Code": Code.Combinations Count.of.ID 1 A, B 2 2 A, C 2 3 A, D 1 4 B, C 3 5 B, D 3 6 C, D 2 I have searched for solution(s) online, so far haven't been able to achieve the desired result. Any help would be appreciated. Thanks! 回答1: Here is a data.table way to solve