Quite a challenge, to be honest. This is basically an extension of the question I asked earlier - Count unique column values ββin pairs by combinations of another column in R
Let's say this time I have the following data frame in R:
data.frame(Reg.ID = c(1,1,2,2,2,3,3), Location = c("X","X","Y","Y","Y","X","X"), Product = c("A","B","A","B","C","B","A"))
The data is as follows:
Reg.ID Location Product 1 1 XA 2 1 XB 3 2 YA 4 2 YB 5 2 YC 6 3 XB 7 3 XA
I would like to count the unique values ββof the Reg.ID column by pairwise combinations of the values ββin the Product column, grouped by the Location column. The result should look like this:
Location Prod.Comb Count 1 XA,B 2 2 YA,B 1 3 YA,C 1 4 YB,C 1
I tried to get the result using the basic R functions, but did not get any success. I assume there is a fairly simple solution using the data.table package in R?
Any help would be greatly appreciated. Thanks!