Skip to content

Sum all values.

Source code

Description

Syntactic sugar for pl$col(…)$sum().

Usage

pl$sum(...)

Arguments

Characters indicating the column names, passed to pl$col(). See ?pl_col for details.

Value

Expr

See Also

  • \$sum()
  • pl$sum_horizontal()

Examples

library("polars")

df = pl$DataFrame(col_a = 1:2, col_b = 3:4, c = 5:6)

df$select(pl$sum("col_a"))
#> shape: (1, 1)
#> ┌───────┐
#> │ col_a │
#> │ ---   │
#> │ i32   │
#> ╞═══════╡
#> │ 3     │
#> └───────┘
# Sum multiple columns
df$select(pl$sum("col_a", "col_b"))
#> shape: (1, 2)
#> ┌───────┬───────┐
#> │ col_a ┆ col_b │
#> │ ---   ┆ ---   │
#> │ i32   ┆ i32   │
#> ╞═══════╪═══════╡
#> │ 3     ┆ 7     │
#> └───────┴───────┘
df$select(pl$sum("^col_.*$"))
#> shape: (1, 2)
#> ┌───────┬───────┐
#> │ col_a ┆ col_b │
#> │ ---   ┆ ---   │
#> │ i32   ┆ i32   │
#> ╞═══════╪═══════╡
#> │ 3     ┆ 7     │
#> └───────┴───────┘