title: How to sum project values in column based on unique project ID?
body: <p>So to describe my question, I created a simplified dataframe like this:</p>
  
  <pre><code>df_test &lt;- data.frame(
    proj_manager = c('Emma','Emma','Emma','Emma','Emma','Alice','Alice'),
    proj_ID = c(1, 1, 2, 2, 2, 3, 4), 
    stage = c('B','B','B','B','B','A','C'),
    value = c(15,15,20,20,20,70,5)
  )
  </code></pre>
  
  <p>And I need to do some calculation on columns to prepare for viz. I created a new column that count the project based on project manager and project stage. I did:</p>
  
  <pre><code>input &lt;- df_test %&gt;%
    group_by(proj_manager, stage) %&gt;%
    mutate(count_proj = length(unique(proj_ID)))
  </code></pre>
  
  <p>Now the data frame looks like this:</p>
  
  <pre><code>proj_manager proj_ID  stage value count_proj
      &lt;fctr&gt;   &lt;dbl&gt; &lt;fctr&gt; &lt;dbl&gt;      &lt;int&gt;
  1         Emma       1      B    15          2
  2         Emma       1      B    15          2
  3         Emma       2      B    20          2
  4         Emma       2      B    20          2
  5         Emma       2      B    20          2
  6        Alice       3      A    70          1
  7        Alice       3      C     5          1
  </code></pre>
  
  <p>I want to create another column named'sum_value' that calculate the sum value of the project based on the same stage, but only different projects. For example, Emma has 'proj_ID 1' and 'proj_ID 2' in stage B, then the new column would sum the value of proj 1 and proj 2.  mutate(sum_value = sum(unique(value))) would do the trick for this simplified dataset, but when two different project ran into the same value, it would lead to an error. </p>
  
  <p>Desired output would look like this:</p>
  
  <pre><code>proj_manager proj_ID  stage value count_proj sum_value
          &lt;fctr&gt;   &lt;dbl&gt; &lt;fctr&gt; &lt;dbl&gt;      &lt;int&gt;     &lt;dbl&gt;
  1         Emma       1      B    15          2        35
  2         Emma       1      B    15          2        35
  3         Emma       2      B    20          2        35
  4         Emma       2      B    20          2        35
  5         Emma       2      B    20          2        35
  6        Alice       3      A    70          1        70
  7        Alice       3      C     5          1         5
  </code></pre>
  
  <p>Any good ideas?</p>