0

Having the following dataframe:

A   | B
--------
abc | 5
def | 2
abc | 4
ghi | 2
def | 1

How can I sum B grouping by A?

Sample output:

A   | B
--------
abc | 9
def | 3
ghi | 2

Thanks!

Diogo Santos
  • 780
  • 4
  • 17
  • Try `aggregate(B~ A, df1, sum)` or `dplyr` `df1 %>% group_by(A) %>% summarise(B = sum(B))` or using `rowsum` `rowsum(df1$B, df1$A)` – akrun Apr 16 '19 at 20:39
  • 1
    [Take a look at this answer](https://stackoverflow.com/a/16657546/1315767) – Jilber Urbina Apr 16 '19 at 20:48

0 Answers0