Skip to content

Index of a sort

Source code

Description

Get the index values that would sort this column.

Usage

<Expr>$arg_sort(descending = FALSE, nulls_last = FALSE)

Arguments

descending A logical. If TRUE, sort in descending order.
nulls_last A logical. If TRUE, place null values last insead of first.

Value

Expr

See Also

pl$arg_sort_by() to find the row indices that would sort multiple columns.

Examples

library(polars)

pl$DataFrame(
  a = c(6, 1, 0, NA, Inf, NaN)
)$with_columns(arg_sorted = pl$col("a")$arg_sort())
#> shape: (6, 2)
#> ┌──────┬────────────┐
#> │ a    ┆ arg_sorted │
#> │ ---  ┆ ---        │
#> │ f64  ┆ u32        │
#> ╞══════╪════════════╡
#> │ 6.0  ┆ 3          │
#> │ 1.0  ┆ 2          │
#> │ 0.0  ┆ 1          │
#> │ null ┆ 0          │
#> │ inf  ┆ 4          │
#> │ NaN  ┆ 5          │
#> └──────┴────────────┘