Skip to contents

Convert a numeric ranking variable to fractional ranks in (0, 1) using average ranks for ties. This is the standard rank definition used in concentration-index calculations.

Usage

fractional_rank(x, ties_method = "average", na_rm = FALSE)

Arguments

x

An atomic vector to rank.

ties_method

Tie-handling method passed to data.table::frankv(). Only "average" is supported.

na_rm

Logical scalar. If TRUE, missing values are dropped before ranking. If FALSE, missing values trigger an error.

Value

A numeric vector of fractional ranks with length equal to the number of retained observations.

Examples

fractional_rank(c(10, 20, 20, 40))
#> [1] 0.125 0.500 0.500 0.875
fractional_rank(c(1, NA, 3), na_rm = TRUE)
#> [1] 0.25 0.75