Skip to content

Sort values in an array

Source code

Description

Sort values in an array

Usage

<Expr>$arr$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.

Examples

library("polars")

df = pl$DataFrame(
  values = list(c(2, 1), c(3, 4), c(NA_real_, 6)),
  schema = list(values = pl$Array(pl$Float64, 2))
)
df$with_columns(sort = pl$col("values")$arr$sort(nulls_last = TRUE))
#> shape: (3, 2)
#> ┌───────────────┬───────────────┐
#> │ values        ┆ sort          │
#> │ ---           ┆ ---           │
#> │ array[f64, 2] ┆ array[f64, 2] │
#> ╞═══════════════╪═══════════════╡
#> │ [2.0, 1.0]    ┆ [1.0, 2.0]    │
#> │ [3.0, 4.0]    ┆ [3.0, 4.0]    │
#> │ [null, 6.0]   ┆ [6.0, null]   │
#> └───────────────┴───────────────┘