Skip to content

Retrieve the index of the maximum value in every sub-list

Description

Retrieve the index of the maximum value in every sub-list

Usage

<Expr>$list$arg_max()

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(s = list(1:2, 2:1))
df$with_columns(
  arg_max = pl$col("s")$list$arg_max()
)
#> shape: (2, 2)
#> ┌───────────┬─────────┐
#> │ s         ┆ arg_max │
#> │ ---       ┆ ---     │
#> │ list[i32] ┆ u32     │
#> ╞═══════════╪═════════╡
#> │ [1, 2]    ┆ 1       │
#> │ [2, 1]    ┆ 0       │
#> └───────────┴─────────┘