title: Create a new column based on the sum of values from another column, with dplyr
body: <p>I'd like to create a new variable called POPULATION that takes up the sum of the values of the variable P1 grouped by the variable CODASC. It seemed easy to me at the beginning, but I'm eventually struggling. Since I have to do this for a lot of variables and for several datasets, I really need a quick way of doing it! If anyone can help me, I would really appreciate it!
  Many thanks,
  Ilaria</p>
  <p>My data frame looks like that:</p>
  <pre><code>PROCOM      SEZ2011   SEZ CODASC    P1   P47   P62  P131    E1    E3  ST15   A46
     &lt;int&gt;        &lt;dbl&gt; &lt;int&gt;  &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt;
  1  48017 480000000000 60001      4   251    25     9    20    70    40    19    20
  2  48017 480000000000 60002      3    15     1     0     1     4     4     0     3
  3  48017 480000000000 60003      2    20     7     2     1     1     1     1     1
  4  48017 480000000000 60004      3   253    21     4    10    63    40    49    22
  5  48017 480000000000 60005      5     3     0     1     0     1     1     0     2
  6  48017 480000000000 60006      1   161    19     7     5    27    17    26    13
  &gt;
  </code></pre>
  <p>And my code looks like that:</p>
  <pre><code>df &lt;- df %&gt;%
    group_by(CODASC) %&gt;%
    mutate(POPULATION = sum(P1 , na.rm= T))
  </code></pre>