Skip to content

Get unique values in an array

Source code

Description

Get unique values in an array

Usage

<Expr>$arr$unique(maintain_order = FALSE)

Arguments

maintain_order If TRUE, the unique values are returned in order of appearance.

Value

Expr

Examples

library(polars)

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