Skip to content

Compute the median value of the sub-arrays

Description

Compute the median value of the sub-arrays

Usage

<Expr>$arr$median()

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(
  values = list(c(2, 1, 4), c(8.4, 3.2, 1)),
)$cast(pl$Array(pl$Float64, 3))
df$with_columns(median = pl$col("values")$arr$median())
#> shape: (2, 2)
#> ┌─────────────────┬────────┐
#> │ values          ┆ median │
#> │ ---             ┆ ---    │
#> │ array[f64, 3]   ┆ f64    │
#> ╞═════════════════╪════════╡
#> │ [2.0, 1.0, 4.0] ┆ 2.0    │
#> │ [8.4, 3.2, 1.0] ┆ 3.2    │
#> └─────────────────┴────────┘