Skip to content

LazyGroupBy_agg

Source code

Description

aggregate a polar_lazy_group_by

Usage

<LazyGroupBy>$agg(...)

Arguments

exprs to aggregate over. … args can also be passed wrapped in a list $agg(list(e1,e2,e3))

Value

A new LazyFrame object.

Examples

library("polars")

lgb = pl$DataFrame(
  foo = c("one", "two", "two", "one", "two"),
  bar = c(5, 3, 2, 4, 1)
)$
  lazy()$
  group_by("foo")


print(lgb)
#> polars LazyGroupBy: 
#> LazyGroupBy (internals are opaque)
lgb$
  agg(
  pl$col("bar")$sum()$name$suffix("_sum"),
  pl$col("bar")$mean()$alias("bar_tail_sum")
)
#> polars LazyFrame
#>  $explain(): Show the optimized query plan.
#> 
#> Naive plan:
#> AGGREGATE
#>  [col("bar").sum().alias("bar_sum"), col("bar").mean().alias("bar_tail_sum")] BY [col("foo")] FROM
#>   DF ["foo", "bar"]; PROJECT */2 COLUMNS; SELECTION: None