Transform numeric values with the integers of their rank (i.e., 1st smallest, 2nd smallest, 3rd smallest, etc.). Setting the sign argument to TRUE will give you signed ranks, where the ranking is done according to absolute size but where the sign is preserved (i.e., 2, 1, -3, 4).

ranktransform(x, ...)

# S3 method for numeric
ranktransform(x, sign = FALSE, method = "average", verbose = TRUE, ...)

# S3 method for grouped_df
ranktransform(
  x,
  select = NULL,
  exclude = NULL,
  sign = FALSE,
  method = "average",
  ...
)

# S3 method for data.frame
ranktransform(
  x,
  select = NULL,
  exclude = NULL,
  sign = FALSE,
  method = "average",
  ...
)

Arguments

x

Object.

...

Arguments passed to or from other methods.

sign

Logical, if TRUE, return signed ranks.

method

Treatment of ties. Can be one of "average" (default), "first", "last", "random", "max" or "min". See rank() for details.

verbose

Toggle warnings and messages on or off.

select

Character vector of column names. If NULL (the default), all variables will be selected.

exclude

Character vector of column names to be excluded from selection.

Value

A rank-transformed object.

See also

Other transform utilities: change_scale(), normalize(), standardize()

Examples

ranktransform(c(0, 1, 5, -5, -2))
#> [1] 3 4 5 1 2
ranktransform(c(0, 1, 5, -5, -2), sign = TRUE)
#> Warning: Zeros detected. These cannot be sign-rank transformed.
#> [1]   NA  1.0  3.5 -3.5 -2.0

head(ranktransform(trees))
#>   Girth Height Volume
#> 1     1    6.0    2.5
#> 2     2    3.0    2.5
#> 3     3    1.0    1.0
#> 4     4    8.5    5.0
#> 5     5   25.5    7.0
#> 6     6   28.0    9.0