title: How can I create sum of previous days?
body: <p>I have this df with column t. I want to create columns t-1 and t-2 where t-1 gives the sum of two days and t-2 gives the sum of three days. </p>
  
  <pre><code>  year      t  t-1 t-2
  19620101    1   NA  NA
  19630102    2   3   NA
  19640103    3   5   6
  19650104    4   7   9
  19650104    5   9   12
  19650104    6   11  15
  </code></pre>
  
  <p>How can I do this?</p>
  
  <p>Extra question:</p>
  
  <p>Can I do this automatically where I mention acc=3 and the code creates two columns with names (t-1),(t-2) or t1,t2 etc? Because my accumulations vary a lot, having an automatic solution help me a great deal. Thanks!'</p>
  
  <p><strong>Expected Output #2</strong></p>
  
  <pre><code> year      t  t-1 t-2
  19620101    1   NA  NA
  19630102    2   NA   NA
  19640103    3   3   NA
  19650104    4   5   6
  19650104    5   7   9
  19650104    6   9  12
  </code></pre>