Compute the mean horizontally across columns
Description
Compute the mean horizontally across columns
Usage
pl$mean_horizontal(..., ignore_nulls = TRUE)
Arguments
…
|
\<dynamic-dots \> Columns to aggregate horizontally. Accepts
expressions. Strings are parsed as column names, other non-expression
inputs are parsed as literals.
|
ignore_nulls
|
A logical. If TRUE , ignore null values (default). If
FALSE , any null value in the input will lead to a null
output.
|
Value
A polars expression
Examples
library("polars")
df <- pl$DataFrame(
a = c(1, 8, 3),
b = c(4, 5, NA),
c = c("x", "y", "z")
)
df$with_columns(
mean = pl$mean_horizontal("a", "b")
)
#> shape: (3, 4)
#> ┌─────┬──────┬─────┬──────┐
#> │ a ┆ b ┆ c ┆ mean │
#> │ --- ┆ --- ┆ --- ┆ --- │
#> │ f64 ┆ f64 ┆ str ┆ f64 │
#> ╞═════╪══════╪═════╪══════╡
#> │ 1.0 ┆ 4.0 ┆ x ┆ 2.5 │
#> │ 8.0 ┆ 5.0 ┆ y ┆ 6.5 │
#> │ 3.0 ┆ null ┆ z ┆ 3.0 │
#> └─────┴──────┴─────┴──────┘