Skip to content

Aggregate groups

Source code

Description

Get the group indexes of the group by operation. Should be used in aggregation context only.

Usage

<Expr>$agg_groups()

Value

Expr

Examples

library(polars)

df = pl$DataFrame(list(
  group = c("one", "one", "one", "two", "two", "two"),
  value = c(94, 95, 96, 97, 97, 99)
))
df$group_by("group", maintain_order = TRUE)$agg(pl$col("value")$agg_groups())
#> shape: (2, 2)
#> ┌───────┬───────────┐
#> │ group ┆ value     │
#> │ ---   ┆ ---       │
#> │ str   ┆ list[u32] │
#> ╞═══════╪═══════════╡
#> │ one   ┆ [0, 1, 2] │
#> │ two   ┆ [3, 4, 5] │
#> └───────┴───────────┘