Description Usage Arguments Value Author(s) Examples
sum_total()
is a short-hand function to calculate and insert the sum
of a category in a data frame.
1 2 3 |
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 |
|
a data frame
Michaja Pehl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | require(dplyr)
data <- expand.grid(
UPPER = LETTERS[1:2],
lower = letters[24:26],
number = 1:2
) %>%
arrange(UPPER, lower, number) %>%
mutate(value = 1:n())
print(data)
data.totals <- data %>%
# grouping is preserved through the summation
group_by(UPPER) %>%
sum_total(lower)
print(data.totals)
data.totals %>%
filter(!(lower == "Total" & number == 2)) %>%
# existing totals are filtered out
sum_total_("lower")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.