Skip to content

Return a boolean mask indicating the first occurrence of each distinct value

Description

Return a boolean mask indicating the first occurrence of each distinct value

Usage

<Expr>$is_first_distinct()

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(a = c(1, 1, 2, 3, 2))
df$with_columns(
  is_first_distinct = pl$col("a")$is_first_distinct()
)
#> shape: (5, 2)
#> ┌─────┬───────────────────┐
#> │ a   ┆ is_first_distinct │
#> │ --- ┆ ---               │
#> │ f64 ┆ bool              │
#> ╞═════╪═══════════════════╡
#> │ 1.0 ┆ true              │
#> │ 1.0 ┆ false             │
#> │ 2.0 ┆ true              │
#> │ 3.0 ┆ true              │
#> │ 2.0 ┆ false             │
#> └─────┴───────────────────┘