Skip to content

Sum all values

Description

This function is syntactic sugar for col(names)$sum().

Usage

pl$sum(...)

Arguments

Name(s) of the columns to use in the aggregation.

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(
  a = c(1, 8, 3),
  b = c(4, 5, 2),
  c = c("foo", "bar", "foo")
)

# Get the sum of a column
df$select(pl$sum("a"))
#> shape: (1, 1)
#> ┌──────┐
#> │ a    │
#> │ ---  │
#> │ f64  │
#> ╞══════╡
#> │ 12.0 │
#> └──────┘
# Get the sum of multiple columns
df$select(pl$sum("a", "b"))
#> shape: (1, 2)
#> ┌──────┬──────┐
#> │ a    ┆ b    │
#> │ ---  ┆ ---  │
#> │ f64  ┆ f64  │
#> ╞══════╪══════╡
#> │ 12.0 ┆ 11.0 │
#> └──────┴──────┘