本文介绍了有什么方法可以在R中独立地对矩阵的列进行排序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是R中的新手,因此,我确实需要一些帮助.我只想对每一列进行独立排序.感谢您的帮助!

I'm a newbie in R so, I really need some help here. I just want to sort each column independently. Any help is appreciated!

 > mat <- matrix(c(45,34,1,3,4325,23,1,2,5,7,3,4,32,734,2),ncol=3)
 > mat
      [,1] [,2] [,3]
 [1,]   45   23    3
 [2,]   34    1    4
 [3,]    1    2   32
 [4,]    3    5  734
 [5,] 4325    7    2

      [,1] [,2] [,3]
 [1,]    1    1    2
 [2,]    3    2    3
 [3,]   34    5    4
 [4,]   45    7   32
 [5,] 4325    23 734

推荐答案

是的,有!

apply(mat, 2, sort)
     [,1] [,2] [,3]
[1,]    1    1    2
[2,]    3    2    3
[3,]   34    5    4
[4,]   45    7   32
[5,] 4325   23  734

这篇关于有什么方法可以在R中独立地对矩阵的列进行排序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 05:27