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)



A numeric, complex, character or logical vector.


Type of ranking: "desc" or "asc" (see Details).


For controlling the treatment of NAs. If TRUE, missing values in the data are put last; if FALSE, they are put first; if NA, they are removed; if "keep" they are kept with rank NA.


A character string specifying how ties are treated (see Details). Can be abbreviated.


Value of digits for round().


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 10
round_rank(10:1, type = "asc")
#> [1] 10 9 8 7 6 5 4 3 2 1
set.seed(334) x <- 10^(-10) * runif(10) round_rank(x)
#> [1] 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.5