How to sort a matrix by all columns

后端 未结 4 1405
灰色年华
灰色年华 2020-12-15 10:04

Suppose I have

arr = 2 1 3
      1 2 3
      1 1 2

How can I sort this into the below?

arr = 1 1 2
      1 2 3
      2 1 3
         


        
4条回答
  •  無奈伤痛
    2020-12-15 10:36

    I had a similar problem, and solution seems to be simple and elegant:

    t(apply(t(yourMatrix),2,sort))
    

提交回复
热议问题