Correlation
Description
Calculates the correlation between two columns
Usage
pl$corr(a, b, method = "pearson", ddof = 1, propagate_nans = FALSE)
Arguments
a
|
One column name or Expr or anything convertible Intopl$col() .
|
b
|
Another column name or Expr or anything convertible Intopl$col() .
|
method
|
str One of ‘pearson’ or ‘spearman’ |
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. |
propagate_nans
|
bool Used only when calculating the spearman rank correlation. If
True any NaN encountered will lead to
NaN in the output. Defaults to False where
NaN are regarded as larger than any finite number and thus
lead to the highest rank.
|
Value
Expr for the computed correlation
Examples
library("polars")
lf = as_polars_lf(data.frame(a = c(1, 8, 3), b = c(4, 5, 2)))
lf$select(pl$corr("a", "b", method = "spearman"))$collect()
#> shape: (1, 1)
#> ┌─────┐
#> │ a │
#> │ --- │
#> │ f64 │
#> ╞═════╡
#> │ 0.5 │
#> └─────┘