Skip to content

Rolling covariance

Source code

Description

Calculates the rolling covariance between two columns

Usage

pl$rolling_cov(a, b, window_size, min_periods = NULL, ddof = 1)

Arguments

a One column name or Expr or anything convertible Into via pl$col().
b Another column name or Expr or anything convertible Into via pl$col().
window_size int The length of the window
min_periods NULL or int 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.
ddof integer 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.

Value

Expr for the computed rolling covariance

Examples

library("polars")

lf = as_polars_lf(data.frame(a = c(1, 8, 3), b = c(4, 5, 2)))
lf$select(pl$rolling_cov("a", "b", window_size = 2))$collect()
#> shape: (3, 1)
#> ┌──────┐
#> │ a    │
#> │ ---  │
#> │ f64  │
#> ╞══════╡
#> │ null │
#> │ 3.5  │
#> │ 7.5  │
#> └──────┘