Something like that?
Rgames> bar [,1] [,2] [,3] [,4] [,5] [1,] NA NA NA NA NA [2,] 1 NA NA NA 3 [3,] NA NA NA NA NA [4,] 2 NA NA NA 4 [5,] NA NA NA NA NA Rgames> rab<-bar[order(bar[,1]),] Rgames> rab [,1] [,2] [,3] [,4] [,5] [1,] 1 NA NA NA 3 [2,] 2 NA NA NA 4 [3,] NA NA NA NA NA [4,] NA NA NA NA NA [5,] NA NA NA NA NA Rgames> rab[,order(rab[1,])] [,1] [,2] [,3] [,4] [,5] [1,] 1 3 NA NA NA [2,] 2 4 NA NA NA [3,] NA NA NA NA NA [4,] NA NA NA NA NA [5,] NA NA NA NA NA
CHANGE, as Roland noted, in a more general situation that will not come close. Now, if allowed to "mix" rows and columns, this would do this:
for(j in 1:nrow(mfoo)) mat[j,]<-mat[j,order(mat[j,])] for(j in 1:ncol(mat)) mat[,j]<-mat[order(mat[,j]),j]
I suspect that it’s not what I need, so I’ll leave and think about the order of the “criteria”