title: Rollsum with week numbers
body: <p>This question comes from a previous one I posted a while ago:</p>
  
  <p><a href="https://stackoverflow.com/questions/34038731/rollsum-with-fixed-dates">rollsum with fixed dates</a></p>
  
  <p>I can not make the given solution to work. I have a large data set, the interesting columns are:</p>
  
  <pre><code>id = c(145658, 145658, 145658, 145658, 145658, 145658, 145658, 145658, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)
  
  week_number = c(24, 35, 44, 71, 82, 117, 127, 142, 4, 15, 20, 24, 30, 36, 42, 46, 59, 67, 68, 71, 75, 78, 79, 86, 93, 96)
  
  amount = c(51.9, 51.9, 51.9, 51.9, 51.9, 103.8, 51.9, 51.9, 67.9, 67.9, 67.9, 67.9, 67.9, 67.9, 67.9, 67.9, 67.9, 67.9, 101.0, 168.9, 101.0, 101.0, 135.8, 168.9, 168.9, 67.9)
  
  df = data.frame(id = id, week_number = week_number, amount = amount)
  </code></pre>
  
  <p>In reality, I have thousands of id's, and each has different week number. I want to calculate the rollsum on the "amount" column for n past weeks (including the present week) for each id.</p>
  
  <p>An extreme example would be with the past 100 weeks. The results would look like:</p>
  
  <pre><code>past_100wk = c(NA, NA, NA, NA, NA, 363.3, 363.3, 363.8, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)
  </code></pre>
  
  <p>Again, this is an extreme case, but it shows the the results should give NA (or -1) when the row value is not included in the week_number window (100 weeks, in this case).</p>
  
  <p>Thank you! </p>