sum_total | R Documentation |
sum_total()
is a short-hand function to calculate and insert the
(weighted) sum of a extensive (intensive) category in a data frame.
sum_total(data, group, value = NA, name = "Total", na.rm = TRUE, weight = NA)
sum_total_(data, group, value = NA, name = "Total", na.rm = TRUE, weight = NA)
data |
a data frame |
group |
column for which the sum is to be calculated |
value |
column of the numbers to be summed |
name |
entry in column |
na.rm |
|
weight |
column of the weights to be applied, if any |
a data frame
Michaja Pehl
require(dplyr)
(d <- expand.grid(
UPPER = LETTERS[1:2],
lower = letters[24:26],
number = 1:2
) %>%
arrange(UPPER, lower, number) %>%
mutate(value = c(1:6, NA, 8:12)))
sum_total(d, UPPER)
sum_total(d, lower, name = 'sum over lower', na.rm = FALSE)
(e <- tibble(
item = c('large', 'medium', 'small'),
specific.value = c(1, 10, 100),
size = c(1000, 100, 1)))
sum_total(e, item, value = specific.value, name = 'Average', weight = size)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.