This can be done with summarise_each
or in the recent version additional functions like summarise_at
, summarise_if
were introduced for convenient use.
csv %>%
group_by(id_num) %>%
summarise_each(funs(sum))
csv %>%
group_by(id_num) %>%
summarise_at(2:3, sum)
If we are using column names, wrap it with vars
in the summarise_at
csv %>%
group_by(id_num) %>%
summarise_at(names(csv)[-1], sum)
NOTE: In the OP's dataset, the column names for the 2nd and 3rd columns were not specified resulting in something like c.1..2..3..4..5.
Using the vars
to apply the function on the selected column names
csv %>%
group_by(id_num) %>%
summarise_at(vars(c.1..2..3..4..5.), sum)
# # A tibble: 2 × 2
# id_num c.1..2..3..4..5.
# <dbl> <dbl>
#1 1 6
#2 2 9