title: Summing variables by group
body: <p>I am trying to group some rows summing the values of one of the columns. In the example I want to sum votes by districts and parties. My goal is to group municipalities and get party votes within a district. I guess it is very easy but my attempts with <code>aggregate</code> and <code>group_by</code> have not worked so far. Thank you!</p>
  <pre><code>df &lt;- structure(list(municip = c(&quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;B&quot;, &quot;C&quot;, &quot;C&quot;), 
                                 district = c(&quot;one&quot;, &quot;one&quot;, &quot;one&quot;, &quot;one&quot;, &quot;one&quot;, &quot;two&quot;, &quot;two&quot;
                                 ), party = c(&quot;green&quot;, &quot;blue&quot;, &quot;red&quot;, &quot;green&quot;, &quot;blue&quot;, &quot;green&quot;, 
                                              &quot;blue&quot;), votes = c(10, 20, 10, 40, 30, 20, 10)), row.names = c(NA, 
                                                                                                             -7L), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;))
  </code></pre>
  <p><a href="https://i.stack.imgur.com/i4jKN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i4jKN.png" alt="enter image description here" /></a></p>