I have a data frame that looks like the following
foo <- read.table(text="1 VA
1 PE
1 CE
4 PE
3 PE
3 CE
2 PE")
Now I want to sort the data frame according to first row first, which I can do by simply
foo[order(foo$V1),]
which gives the result :
V1 V2
1 1 VA
2 1 PE
3 1 CE
7 2 PE
5 3 PE
6 3 CE
4 4 PE
But my problem now is I want to keeping the sorted result in V1 same, I want to sort it according to second column. The results should look something like
V1 V2
1 1 CE
2 1 PE
3 1 VA
7 2 PE
5 3 CE
6 3 PE
4 4 PE
where first column is as it is but second column, V2 is also sorted something similar to
sort -k1 -k2
in unix