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 o
You can also do something like this- Note- As mentioned by @chinsoon12, we can use pmin & pmax
pmin
pmax
> setDT(dt1)[,list(Count=.N) ,paste(pmin(CAT1, CAT2), pmax(CAT1, CAT2), sep=' & ')] paste Count 1: a & a 1 2: b & b 2 3: c & c 2 4: a & b 2 5: a & c 3