Concatenate two column values alphabetically? or... Unique combinations from columns?

Hi,

I currently have two columns with all the possible combinations from the values of a single category:
Column 1 | Column 2
A | B
A | C
B | A
B | C
C | A
C | B

As you can see, those combinations are not exactly “unique” if we consider that A | B is the same as B | A. I can’t find a way to filter those columns based on unique combinations… any ideas?

My best chance is to create a new column with a concatenation in alphabetical order, so, I would have:

Column 1 | Column 2 | Column 3
A | B | AB
A | C | AC
B | A | AB
B | C | BC
C | A | AC
C | B | BC

With this method would be very easy to remove duplicates. But can’t find a way to concatenate columns based on the alphabetical order.

Any ideas?

I think it can be solved with enumeration and a self-join where Column 1 matches Column 2 and the other way around. In this case, comparing row numbers will tell us whether we had this combination previously or not.

See the example below:

unique-combinations.morph (2.7 KB)

From a theoretical perspective, this is a task of finding loops of length = 2 in a directed graph. Usually, graph calculations are performed using either self-joins (straight-forward in EasyMorph) or matrix multiplications (not that straight-forward, but still doable).

Works perfectly, thanks!! :slight_smile:

Hi,

If you want another way:

image

unique-combinations.morph (4,1 Ko)

2 Likes

it does the trick too!

Thanks!!