I have used Florian’s answer to this question to get the unique pairs separately for the one shared (grouping) variable. Can this be extended to the case where there are two grouping variables, and the pairs should be unique based on either grouping variable?
For example, if the input data is
df = data.frame(scaffold = c("A", "A", "B", "B", "B", "C", "C", "D","A"),
geneID = c("162", "276", "64", "276", "281", "64", "162", "162","64"),
Grouping2 = c("x1", "x2", "x3", "x1", "x2", "x3", "x1", "x2", "x3"),
stringsAsFactors = F)
and my groups are geneID
and Grouping2
, how do I produce all sets of unique pairs for scaffold
? In this toy example, A
and B
pair both on 276
and x1
, but only one A-B pair should be produced?