I have this data-frame:
AAA X_980 X_100 X_990 X_1100 X_2200 X_Y_100 X_Y_2200 X_Y_990 X_Y_1100 X_Y_980 X_10_100 X_10_980 X_10_990 X_10_1100 X_10_2200 X_A X_A_B
100 6 6 6 3 4 1 7 5 1 9 9 2 7 3 7 3 8
980 2 9 5 5 9 3 6 2 1 3 1 8 2 9 4 8 4
990 8 8 7 7 9 3 5 7 3 1 5 5 6 6 1 3 4
1100 6 5 4 7 4 6 2 1 6 2 3 5 3 9 7 5 2
2200 7 4 3 2 4 5 9 1 9 4 6 5 8 7 7 7 9
As you can see, there are 5 unique values in column AAA, and 3 groups of columns: X_, X_Y_, and X_10_, followed by a suffix with each of the unique values. I want to change the order of the columns so each group of columns is sorted by the unique values (ascending).
Expected result:
AAA X_100 X_980 X_990 X_1100 X_2200 X_Y_100 X_Y_980 X_Y_990 X_Y_1100 X_Y_2200 X_10_100 X_10_980 X_10_990 X_10_1100 X_10_2200 X_A X_A_B
100 6 6 6 3 4 1 9 5 1 7 9 2 7 3 7 3 8
980 9 2 5 5 9 3 3 2 1 6 1 8 2 9 4 8 4
990 8 8 7 7 9 3 1 7 3 5 5 5 6 6 1 3 4
1100 5 6 4 7 4 6 2 1 6 2 3 5 3 9 7 5 2
2200 4 7 3 2 4 5 4 1 9 9 6 5 8 7 7 7 9