Rank elements
Description
Assign ranks to data, dealing with ties appropriately.
Usage
<Expr>$rank(
method = c("average", "min", "max", "dense", "ordinal", "random"),
descending = FALSE,
seed = NULL
)
Arguments
method
|
String, one of “average” (default), “min” ,
“max” , “dense” , “ordinal” ,
“random” . The method used to assign ranks to tied elements:
|
descending
|
Rank in descending order. |
seed
|
string parsed or number converted into uint64. Used if method="random". |
Value
Expr
Examples
library("polars")
# The 'average' method:
pl$DataFrame(a = c(3, 6, 1, 1, 6))$
with_columns(rank = pl$col("a")$rank())
#> shape: (5, 2)
#> ┌─────┬──────┐
#> │ a ┆ rank │
#> │ --- ┆ --- │
#> │ f64 ┆ f64 │
#> ╞═════╪══════╡
#> │ 3.0 ┆ 3.0 │
#> │ 6.0 ┆ 4.5 │
#> │ 1.0 ┆ 1.5 │
#> │ 1.0 ┆ 1.5 │
#> │ 6.0 ┆ 4.5 │
#> └─────┴──────┘
# The 'ordinal' method:
pl$DataFrame(a = c(3, 6, 1, 1, 6))$
with_columns(rank = pl$col("a")$rank("ordinal"))
#> shape: (5, 2)
#> ┌─────┬──────┐
#> │ a ┆ rank │
#> │ --- ┆ --- │
#> │ f64 ┆ u32 │
#> ╞═════╪══════╡
#> │ 3.0 ┆ 3 │
#> │ 6.0 ┆ 4 │
#> │ 1.0 ┆ 1 │
#> │ 1.0 ┆ 2 │
#> │ 6.0 ┆ 5 │
#> └─────┴──────┘