Skip to content

Rolling quantile

Source code

Description

Compute the rolling (= moving) quantile over the values in this array. A window of length window_size will traverse the array. The values that fill this window will (optionally) be multiplied with the weights given by the weight vector.

Usage

<Expr>$rolling_quantile(
  quantile,
  interpolation = "nearest",
  window_size,
  weights = NULL,
  min_periods = NULL,
  ...,
  center = FALSE
)

Arguments

quantile Quantile between 0 and 1.
interpolation String, one of “nearest”, “higher”, “lower”, “midpoint”, “linear”.
window_size Integer specifying the length of the window.
weights An optional slice with the same length as the window that will be multiplied elementwise with the values in the window.
min_periods The number of values in the window that should be non-null before computing a result. If NULL, it will be set equal to window size.
Ignored.
center Set the labels at the center of the window

Details

If you want to compute multiple aggregation statistics over the same dynamic window, consider using $rolling() this method can cache the window size computation.

Value

Expr

Examples

library("polars")

pl$DataFrame(a = c(1, 3, 2, 4, 5, 6))$
  with_columns(roll_quant = pl$col("a")$rolling_quantile(0.3, window_size = 2))
#> shape: (6, 2)
#> ┌─────┬────────────┐
#> │ a   ┆ roll_quant │
#> │ --- ┆ ---        │
#> │ f64 ┆ f64        │
#> ╞═════╪════════════╡
#> │ 1.0 ┆ null       │
#> │ 3.0 ┆ 1.0        │
#> │ 2.0 ┆ 2.0        │
#> │ 4.0 ┆ 2.0        │
#> │ 5.0 ┆ 4.0        │
#> │ 6.0 ┆ 5.0        │
#> └─────┴────────────┘