title: Rolling sum in R
body: <pre><code>df &lt;- data.frame(x = seq(1:10))
  </code></pre>
  
  <p>I want this:</p>
  
  <pre><code>df$y &lt;- c(1, 2, 3, 4, 5, 15, 20 , 25, 30, 35)
  </code></pre>
  
  <p>i.e. each <code>y</code> is the sum of previous five <code>x</code> values. This implies the first 
  five <code>y</code> will be same as <code>x</code> </p>
  
  <p>What I get is this:</p>
  
  <pre><code>df$y1 &lt;- c(df$x[1:4], RcppRoll::roll_sum(df$x, 5)) 
  
    x  y y1
    1  1  1
    2  2  2
    3  3  3
    4  4  4
    5  5 15
    6 15 20
    7 20 25
    8 25 30
    9 30 35
    10 35 40
  </code></pre>
  
  <p>In summary, I need <code>y</code> but I am only able to achieve <code>y1</code>      </p>