I am trying to sort a data matrix with several columns. Here, I want to sort sequentially as in Excel. Once I sort the matrix by the first column, I would like to keep the first column, and then sort by the second column, then keep the first and second columns and then sort the rest of the matrix by the third column, and so on.
For example, if my matrix is dd
and I want to sort from 20 to 34 sequentially:
L <- 34
for(init in 20:L){
dd <- dd[with(dd, order(dd[,init],decreasing=T)), ]
}
This does not work; can anyone advise me with a correct script for this case?