Skip to content

Covariance

Source code

Description

Calculates the covariance between two columns / expressions.

Usage

pl$cov(a, b, 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().
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 covariance

Examples

library("polars")

lf = as_polars_lf(data.frame(a = c(1, 8, 3), b = c(4, 5, 2)))
lf$select(pl$cov("a", "b"))$collect()
#> shape: (1, 1)
#> ┌─────┐
#> │ a   │
#> │ --- │
#> │ f64 │
#> ╞═════╡
#> │ 3.0 │
#> └─────┘
pl$cov(c(1, 8, 3), c(4, 5, 2))$to_r()
#> [1] 3