title: Use a value from the previous row in an R data.table calculation
body: <p>I want to create a new column in a data.table calculated from the current value of one column and the previous of another.  Is it possible to access previous rows?</p>
  
  <p>E.g.:</p>
  
  <pre><code>&gt; DT &lt;- data.table(A=1:5, B=1:5*10, C=1:5*100)
  &gt; DT
     A  B   C
  1: 1 10 100
  2: 2 20 200
  3: 3 30 300
  4: 4 40 400
  5: 5 50 500
  &gt; DT[, D := C + BPreviousRow] # What is the correct code here?
  </code></pre>
  
  <p>The correct answer should be</p>
  
  <pre><code>&gt; DT
     A  B   C   D
  1: 1 10 100  NA
  2: 2 20 200 210
  3: 3 30 300 320
  4: 4 40 400 430
  5: 5 50 500 540
  </code></pre>