Skip to content

Compute the mean rowwise

Source code

Description

Compute the mean rowwise

Usage

pl$mean_horizontal(...)

Arguments

Columns to concatenate into a single string column. Accepts expressions. Strings are parsed as column names, other non-expression inputs are parsed as literals.

Value

Expr

Examples

library(polars)

df = pl$DataFrame(
  a = c(1, 8, 3, 6, 7),
  b = c(4, 5, NA_real_, Inf, NaN)
)

df$with_columns(
  pl$mean_horizontal("a", "b")$alias("mean"),
  pl$mean_horizontal("a", "b", 5)$alias("mean_with_lit")
)
#> shape: (5, 4)
#> ┌─────┬──────┬──────┬───────────────┐
#> │ a   ┆ b    ┆ mean ┆ mean_with_lit │
#> │ --- ┆ ---  ┆ ---  ┆ ---           │
#> │ f64 ┆ f64  ┆ f64  ┆ f64           │
#> ╞═════╪══════╪══════╪═══════════════╡
#> │ 1.0 ┆ 4.0  ┆ 2.5  ┆ 3.333333      │
#> │ 8.0 ┆ 5.0  ┆ 6.5  ┆ 6.0           │
#> │ 3.0 ┆ null ┆ 3.0  ┆ 4.0           │
#> │ 6.0 ┆ inf  ┆ inf  ┆ inf           │
#> │ 7.0 ┆ NaN  ┆ NaN  ┆ NaN           │
#> └─────┴──────┴──────┴───────────────┘