I have a dataframe like this:
df <- data.frame(a=c(111,111,111,222,222,222,333,333,333),
b=c(1,0,1,1,1,1,0,0,1))
df
a b
1 111 1
2 111 0
3 111 1
4 222 1
5 222 1
6 222 1
7 333 0
8 333 0
9 333 1
I need to get the sum of column 'b' for each 'a':
A B
1 111 2
2 222 3
3 333 1
How can I do that in the fastest way?