Rolling standard deviation

Source code

Description

Compute the rolling (= moving) standard deviation 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_std(
window_size,
weights = NULL,
min_periods = NULL,
...,
center = FALSE,
ddof = 1
)
``````

Arguments

 `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 `ddof` An integer representing "Delta Degrees of Freedom": the divisor used in the calculation is `N - ddof`, where `N` represents the number of elements. By default ddof is `1`.

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.

Expr

Examples

``````library(polars)

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