title: Add row value to previous row value in R
body: <p>I have a very basic question as I am relatively new to R. I was wondering how to add a value in a column to the previous value and repeat right down a column of 1000s of values? Note, I do not want a cumulative sum and therefore the cumsum function is of no use. Say my column is called WD, I want to add WD1 to WD2, WD2 to WD3, WD3 to WD4 etc. all the way down and output these sums as a new column. Is there an easy way? Many thanks.</p>
  
  <p>A reproducible example:</p>
  
  <pre><code>set.seed(111)
  df1 &lt;- data.frame(WD=sample(10))
  
  #result
  df1
     WD new
  1   6   6
  2   7  13
  3   3  10
  4   4   7
  5   8  12
  6  10  18
  7   1  11
  8   2   3
  9   9  11
  10  5  14
  </code></pre>