Skip to content

Cumulative evaluation of expressions

Source code

Description

Run an expression over a sliding window that increases by 1 slot every iteration.

Usage

<Expr>$cumulative_eval(expr, min_periods = 1L, parallel = FALSE)

Arguments

expr Expression to evaluate.
min_periods Number of valid (non-null) values there should be in the window before the expression is evaluated.
parallel Run in parallel. Don’t do this in a groupby or another operation that already has much parallelization.

Details

This can be really slow as it can have O(n^2) complexity. Don’t use this for operations that visit all elements.

Value

Expr

Examples

library("polars")

pl$lit(1:5)$cumulative_eval(
  pl$element()$first() - pl$element()$last()^2
)$to_r()
#> [1]   0  -3  -8 -15 -24