'Summarise multiple columns using dplyr R [duplicate]

Let's say I have this dataframe:

Agency    Submissions   Population    County
1         36            1500          Jackson
2         0             800           Jackson
3         12            1400          Jackson
4         12            1402          Adams
5         36            4800          Adams
6         36            3400          Adams

How do I summarize by both submissions and population, by County, to get something like:

County   Submissions   Population
Jackson  48            3700
Adams    84            9602

I've tried using dplyr but can only summarize 1 column at a time.



Solution 1:[1]

Try this:

df %>%
  group_by(County) %>%
  summarise(across(c(Submissions, Population), sum))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 eastclintw00d