我正在尝试根据最终列值对 R 中的现有矩阵进行重新排序,但我似乎找不到解决方案。我试过 order(),但没有运气。我显然忽略了一些东西。有任何想法吗?例如,假设我们创建了一个包含 5 列数据的矩阵:
> a <-matrix(100+rnorm(50),10,5)
> a
[,1] [,2] [,3] [,4] [,5]
[1,] 101.26878 99.36657 99.32874 99.46449 101.46698
[2,] 102.28284 102.62506 100.21430 100.54780 100.14608
[3,] 99.25180 100.93911 101.31455 99.92939 99.87537
[4,] 99.69423 99.17830 99.20230 99.42162 100.70614
[5,] 99.03745 99.95904 100.85773 98.39691 100.84777
[6,] 100.09040 101.66841 98.73320 97.41576 99.36144
[7,] 99.94181 100.18932 101.26947 99.81551 99.30574
[8,] 99.15694 98.24990 98.81500 99.26529 100.72547
[9,] 100.52822 99.43562 101.73370 98.32482 99.30498
[10,] 100.37140 99.54621 99.37048 99.43794 101.28328
如何根据最终值重新排序列并将结果保存在矩阵中?例如,列 [,5] 具有最高的最终值 (101.28328),因此它将被列在最左端的第一位;列 [,1] 将是第二个,依此类推。谢谢!