I have a numeric matrix like this:
5 2 4 6 1
2 3 3 2 5
1 1 4 5 2
3 6 2 1 0
I want to sort it by the rows of the last column to get a matrix like:
3 6 2 1 0
5 2 4 6 1
1 1 4 5 2
2 3 3 2 5
I tried to run this code:
t <- function(m){
b <- sapply(1:length(m[,1]),function(x){sort(m[x,5],decreasing=F)})
m[b,]
}
But it doesn't work. Do you suggest anything?