I know strictly programming question are out of skope on this platform, but I was wondering if any of you might have an answer for what I want to do. I am completly new in R, or coding.
This is an example of my data:
X1 year individual partner
<dbl> <dbl> <chr> <chr>
1 1 2015 A B
2 2 2015 A B
3 3 2015 B A
4 4 2015 C A
5 5 2015 C D
6 6 2015 D C
I want to create a new column which will give me the id of the dyad. A dyad will be a unique combination of individual and partner. I can merge the columns together, but in that case A_B and B_A will be two different dyads however these two are actually the same dyad.
An example of what I want to achieve:
X1 year individual partner dyad
<dbl> <dbl> <chr> <chr> <chr>
1 1 2015 A B A_B
2 2 2015 A B A_B
3 3 2015 B A A_B
4 4 2015 C A C_A
5 5 2015 C D C_D
6 6 2015 D C C_D
I there a way to merge two columns together but make a rule for how these are combined in the new column which would be appropriate in my case?
Thank you for your help.