Skip to content

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

Description

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

Usage

<Expr>$is_last_distinct()

Value

A polars expression

Examples

library("polars")

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