order()表现不如预期

时间:2015-11-30 17:44:39

标签: r

确定。我很相信我即将让自己难堪,但我们走了。

我无法让order()正常工作。我试图通过两个不同的因素得出一个综合排名,下面将举例说明如下:

test1 <- rnorm(5)
test2 <- abs(rnorm(5))
test1; test2
> 0.4839582  0.1665794 -0.7648058 -0.5492701  0.6616983
> 0.8491913 0.2840523 2.3413548 0.7299879 0.1584666
test1Ord <- order(test1, decreasing = TRUE)
test2Ord <- order(test2)
test3Ord <- test1Ord + test2Ord
test1Ord; test2Ord; test3Ord 
> 5 1 2 4 3
> 5 2 4 1 3
> 10  3  6  5  6
order(as.numeric(test3Ord), decreasing = TRUE)
> 1 3 5 4 2

正如你所看到的,矢量c(10,3,6,5,6)应按1,5,3,4,2或1,5,2,4,3的顺序排列(因为6的关系) )。这不是输出。

我错过了什么吗?!

1 个答案:

答案 0 :(得分:1)

看起来我正在寻找排名()。 (我以前没有意识到这个功能。)我对order()非常熟悉,但在我试图做的事情上混淆了。

向量的rank()提供了我想要的东西。

感谢所有人为我做好准备!