Sum column with a condition in R
<p>I have a dataframe like this:</p>

<pre><code>df &lt;- 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
</code></pre>

<p>I need to get the sum of column 'b' for each 'a':</p>

<pre><code>    A B
1 111 2
2 222 3
3 333 1
</code></pre>

<p>How can I do that in the fastest way?</p>