This is a job for group_by() and summarise().
library(dplyr, warn.conflicts = FALSE)
df <- data.frame(
stringsAsFactors = FALSE,
a = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3),
b = c("a", "a", "b", "b", "c", "a", "a", "a", "b", "a", "a"),
c = c(11, 22, 33, 44, 55, 66, 77, 88, 99, 12, 14)
)
df %>%
group_by(a, b) %>%
summarise(d = sum(c), .groups = "drop")
#> # A tibble: 6 x 3
#> a b d
#> <dbl> <chr> <dbl>
#> 1 1 a 33
#> 2 1 b 77
#> 3 1 c 55
#> 4 2 a 231
#> 5 2 b 99
#> 6 3 a 26
Created on 2020-06-10 by the reprex package (v0.3.0)