I need some help in sorting data that has more than 100 objects and thousands of variables and I want to sort them according to numeric order. (E.g. 1,2,3,4)
This is a sample Dataframe
df <- data.frame(P1 = 1:10, P5 = 11:20, P3 = 6:15, P2 = 21:30, P15 = 35:26)
print(df)
P1 P5 P3 P2 P15
1 1 11 6 21 35
2 2 12 7 22 34
3 3 13 8 23 33
4 4 14 9 24 32
5 5 15 10 25 31
6 6 16 11 26 30
7 7 17 12 27 29
8 8 18 13 28 28
9 9 19 14 29 27
10 10 20 15 30 26
But I want the columns to be ordered by their names as shown by the table below
P1 P2 P3 P5 P15
1 1 21 6 11 35
2 2 22 7 12 34
3 3 23 8 13 33
4 4 24 9 14 32
5 5 25 10 15 31
6 6 26 11 16 30
7 7 27 12 17 29
8 8 28 13 18 28
9 9 29 14 19 27
10 10 30 15 20 26
And also I am not using any libraries which basically is base-R.