title: Cumulative percentages in R
body: <p>I have the following data frame</p>
  
  <pre><code>d2
  # A tibble: 10 x 2
    ID Count
  &lt;int&gt; &lt;dbl&gt;
    1     1
    2     1
    3     1
    4     1
    5     1
    6     2
    7     2
    8     2
    9     3
   10     3
  </code></pre>
  
  <p>Which states how many counts each person (ID) had.</p>
  
  <p>I would like to calculate the cumulative percentage of each count: 1 - 50%, up to 2: 80%, up to 3: 100%.
  I tried</p>
  
  <pre><code>&gt; d2 %&gt;% mutate(cum = cumsum(Count)/sum(Count))
  # A tibble: 10 x 3
    ID   Count     cum
   &lt;int&gt; &lt;dbl&gt;    &lt;dbl&gt;
     1     1   0.05882353
     2     1   0.11764706
     3     1   0.17647059
     4     1   0.23529412
     5     1   0.29411765
     6     2   0.41176471
     7     2   0.52941176
     8     2   0.64705882
     9     3   0.82352941
    10     3   1.00000000
  </code></pre>
  
  <p>but this result is obviously incorrect because I would expect that the count of 1 would correspond to 50% rather than 29.4%.</p>
  
  <p>What is wrong here? How do I get the correct answer?</p>