Count the number of unique values in every sub-lists
Description
Count the number of unique values in every sub-lists
Usage
<Expr>$list$n_unique()
Value
A polars expression
Examples
library("polars")
df <- pl$DataFrame(values = list(c(2, 2, NA), c(1, 2, 3), NA))
df$with_columns(unique = pl$col("values")$list$n_unique())
#> shape: (3, 2)
#> ┌──────────────────┬────────┐
#> │ values ┆ unique │
#> │ --- ┆ --- │
#> │ list[f64] ┆ u32 │
#> ╞══════════════════╪════════╡
#> │ [2.0, 2.0, null] ┆ 2 │
#> │ [1.0, 2.0, 3.0] ┆ 3 │
#> │ [null] ┆ 1 │
#> └──────────────────┴────────┘