Skip to content

Compute the sum rowwise

Source code

Description

Compute the sum rowwise

Usage

pl$sum_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 = NA_real_,
  b = c(3:4, NA_real_, NA_real_),
  c = c(1:2, NA_real_, -Inf)
)
df$with_columns(
  pl$sum_horizontal("a", "b", "c", 2)$alias("sum")
)
#> shape: (4, 4)
#> ┌──────┬──────┬──────┬──────┐
#> │ a    ┆ b    ┆ c    ┆ sum  │
#> │ ---  ┆ ---  ┆ ---  ┆ ---  │
#> │ f64  ┆ f64  ┆ f64  ┆ f64  │
#> ╞══════╪══════╪══════╪══════╡
#> │ null ┆ 3.0  ┆ 1.0  ┆ 6.0  │
#> │ null ┆ 4.0  ┆ 2.0  ┆ 8.0  │
#> │ null ┆ null ┆ null ┆ 2.0  │
#> │ null ┆ null ┆ -inf ┆ -inf │
#> └──────┴──────┴──────┴──────┘