Function for ranking vector after rounding.
round_rank(x, type = "desc", na.last = TRUE, ties = c("average", "first",
"last", "random", "max", "min"), round_digits = 7)
| x | A numeric, complex, character or logical vector. |
|---|---|
| type | Type of ranking: |
| na.last | For controlling the treatment of |
| ties | A character string specifying how ties are treated (see Details). Can be abbreviated. |
| round_digits | Value of |
A numeric vector of the same length as x with names copied from x
(unless na.last = NA, when missing values are removed). The vector is of
integer type unless x is a long vector or ties = "average" when it is of
double type (whether or not there are any ties).
This is basically a wrapper around rank() in which x is
pre-modified by rounding to specific number of digits round_digits.
type can have two values: "desc" for ranking in descending order (rank 1
is given to the biggest value in x) and "asc" (rank 1 is given to the
smallest value in x). Any other value will cause error.
round_rank(10:1, type = "desc")#> [1] 1 2 3 4 5 6 7 8 9 10round_rank(10:1, type = "asc")#> [1] 10 9 8 7 6 5 4 3 2 1#> [1] 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5