Sum up all numeric columns in a data frame

add_total_column(.data, name = "Total")

Arguments

.data

A tbl.

name

The output column name. If omitted, it will be Total.

Value

An object of the same class as .data

Examples

df <- data.frame(id = LETTERS[1:3], x1 = 1:3, x2 = 4:6, x3 = 7:9) df
#> id x1 x2 x3 #> 1 A 1 4 7 #> 2 B 2 5 8 #> 3 C 3 6 9
df %>% add_total_column()
#> id x1 x2 x3 Total #> 1 A 1 4 7 12 #> 2 B 2 5 8 15 #> 3 C 3 6 9 18