Extending rank() “Olympic Style”

醉酒当歌 提交于 2021-02-16 18:43:16

问题


In the olympics, if two people are tied for silver - they don't give out a bronze medal.

Here's a sample of the kind of data I'm working with:

x <- c(0.64, 0.64, 0.63, 0.62, 0.62, 0.62, 0.61, 0.6, 0.6, 0.58)

I'd like to create a ranking function that outputs like so:

rank.fun(x) 
1 1 3 4 4 4 7 8 8 10 

I've tried messing around with findInterval, rank, floor, ceiling but none of them seem to provide the result I'm looking for.


回答1:


How about this: rank(-x, ties.method="min")




回答2:


It looks like you can do this with rank:

> rank(-x, ties="min")
 [1]  1  1  3  4  4  4  7  8  8 10


来源:https://stackoverflow.com/questions/9071143/extending-rank-olympic-style

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!