I have a data table with three columns. The first two are a collection of the data points (categorical data that can be either A, B, or C). The third column is a concatenation of the two data points as they belong to a set. I need to get the counts of the possible combinations and need to count "A & C" as part of the same group as "C & A" since the order of these pairs doesn't matter.
Previously, I set up a column that concatenated "CAT1 & CAT2" and then another as "CAT2 & CAT1" hoping to sum up there, but those numbers of course don't add up properly then.
library(data.table)
dt1 = data.table(CAT1 = c('a','b','c','b','a','c','c','b','a','c'),
CAT2 = c('a','b','c','a','b','c','a','b','c','a'))
dt1[,merged := paste(dt1$CAT1, dt1$CAT2, sep = ' & ')]
counts = data.table(table(dt1$merged))
The output table "counts" gives me all the uniques of the merged column, but I need to sum up anywhere the data points are flipped ("A & C" + "C & A"). I recognize that this could be done manually, but I have far too many actual data points to do by hand.