title: cumsum starting over after NA
body: <p>I have a dataframe with multiple columns. For one column I would like to calculate the cumulative sums but I have some trouble with missing values.</p>
  
  <pre><code>#sample data
  test &lt;- c(-1.2, 4.6, -8.3, 5, 8, 1, -2, NA, NA, NA, -3, 5.1, 1.9)
  test &lt;- as.data.frame(test)
  
  #This gives NA after NAs occurred
  sum_test &lt;- lapply(test, FUN=cumsum)
  
  sum_test
  $test
   [1] -1.2  3.4 -4.9  0.1  8.1  9.1  7.1   NA   NA   NA   NA   NA   NA
  
  #This continues with adding to pre-NA value after last NA
  sum_test &lt;- lapply(test, function(x) ave(x, is.na(x), FUN=cumsum))
  
  sum_test
  $test
   [1] -1.2  3.4 -4.9  0.1  8.1  9.1  7.1   NA   NA   NA  4.1  9.2 11.1
  </code></pre>
  
  <p>However, what I would like to achieve is that after the NAs cumsum starts over:</p>
  
  <pre><code>-1.2  3.4 -4.9  0.1  8.1  9.1  7.1   NA   NA   NA -3   2.1   4
  </code></pre>
  
  <p>Can this be done?</p>