Link rank in R

I have a list of competitors and points from the tournament. Many competitors are connected. I need a way to rank them in R, so, for example, if four competitors are tied to fourth place, the result might look like this:

Competitor A: 1 
Competitor B: 2
Competitor C: 3
Competitor D: 4
Competitor E: 4
Competitor F: 4
Competitor G: 4
Competitor F: 8

So, the next rank after the tie, and not 5, will be 8 (because four participants took slots from 4-7).

I know this is a bit contrasting intuitive, but if anyone has any ideas, that would be much appreciated. Thank you

data

v1 <- setNames(c(4, 5, 2, 7, 7, 7, 7, 9), paste('Competitor', LETTERS[1:8]))
+4
source share
1 answer

We can use min_rankfromdplyr

library(dplyr)
min_rank(v1)
#[1] 2 3 1 4 4 4 4 8

Or in base R, (from @Steven Beaupré's comments)

rank(v1, ties.method = "min")

data

v1 <- c(4, 5, 2, 7, 7, 7, 7, 9)
+5
source

Source: https://habr.com/ru/post/1615884/


All Articles