rank() vs min_rank()

Hi,

I'm learning now the basics of dplyr and I am getting confused with rank() and min_rank().

Could someone explain me the difference? Would be very grateful!! :slight_smile: :slightly_smiling_face:

Karen

The rank() function has several ways of handling ties. The min_rank() function is a function that returns the same values as rank when the ties_method is set to "min", that is, ties are assigned the minimum ranking possible. For example, if two elements are the second lowest in the vector, they are assigned the rank 2 and there is no rank 3. An alternative is to give them the rank 3 and have no ranking of 2.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

X <- c(24,22,22,23,21)
min_rank(X)
#> [1] 5 2 2 4 1
rank(X, ties.method = "min")
#> [1] 5 2 2 4 1
rank(X, ties.method = "max")
#> [1] 5 3 3 4 1

Created on 2020-04-06 by the reprex package (v0.3.0)

1 Like

great! Thanks a lot!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.