I have a df like below:
ID P1 P2 P3_1_A P3_2_B P4_1_A P4_2_B
1 110 111 1 0 1 1
2 111 112 0 0 1 0
3 110 112 0 1 0 0
4 112 111 1 1 1 1
So, P1 and P2 has 3 distinct values 110, 111 and 112.
Column P3's and P4's are always equal in number (2 in the above case) but may vary from data to data.
I want a resultant data frame where all the P3 values are aligned to P1 and all P4 values to P2 and columns renamed and looks like below
ID P P_A P_B
1 110 1 0
1 111 1 1
2 111 0 0
2 112 1 0
3 110 0 1
3 112 0 0
4 112 1 1
4 111 1 1
I know how to merge P1 and P2 and get to column P but not getting how to align P3 and P4 to P1 and P2 and get to P_1 and P_2