I have data that look like this:
X Y TOTAL PAIR
1 A B 1 AB
2 B A 2 BA
3 C D 3 CD
4 D C 4 DC
5 E F 5 EF
I want to add a variable PAIR_ID that captures the same IDs in any combination. So the order doesn't matter. It should look like this:
X Y TOTAL PAIR PAIR_ID
1 A B 1 AB 1
2 B A 2 BA 1
3 C D 3 CD 2
4 D C 4 DC 2
5 E F 5 EF 3
The goal is to get a df that has totals for each pair. So something like this:
PAIR_ID PAIR_TOTAL
1 1 3
2 2 7
3 3 5
My question is how to get that PAIR_ID variable. I'm stumped. Appreciate any help.