I would like to create a vector:
c(1,2,4,2,2)
And use rank variable to return:
c(1,2,5,2,2)
How do I use rank?
Asked
Active
Viewed 99 times
0

MrFlick
- 195,160
- 17
- 277
- 295

greasemonkey
- 19
- 6
2 Answers
3
Check out the ?rank
help page for options, specifically the ties.method=
paramter. Specifically the output you want can be generated with ties.method="min"
rank(c(1,2,4,2,2), ties.method = "min")
# [1] 1 2 5 2 2

MrFlick
- 195,160
- 17
- 277
- 295
1
Using min_rank
from dplyr
library(dplyr)
min_rank(c(1,2,4,2,2))
#[1] 1 2 5 2 2

akrun
- 874,273
- 37
- 540
- 662