title: How to rearrange time series data in 10 days time window in R?
body: <p>I am currently working on a timeseries streamflow data range from 2002-10-04 to 2012-10-28, what I need to do is to develop regression models using 10-day time window data. To be more specific, I need to use Oct-04 to Oct 13 across all years from 2002 to 2012 to build a regression model. Then I need to use Oct-05 to Oct 14 across all years from 2002 to 2012 to build another regression model, then use Oct-06 to Oct 15 across all years to build next model and so on repeatedly till the end.</p>
  <p>This is how my data look like.</p>
  <pre><code>&gt; head(CFbasin)
          Data      Qkl     Qllt     Qhaw      Qdp     Qlit
  1 2002-10-04 19.25546 8.353470 4.502379 2.217209 1.985011
  2 2002-10-05 19.56694 8.126935 4.615646 1.622555 1.628219
  3 2002-10-06 19.73684 7.560598 4.389111 1.251605 1.492298
  4 2002-10-07 18.12278 7.079212 3.992675 1.158159 1.413011
  5 2002-10-08 18.12278 6.824360 3.794457 1.070377 1.393189
  6 2002-10-09 17.83961 6.739409 3.369705 1.073208 1.353545
  
  &gt; tail(CFbasin)
             Data      Qkl     Qllt      Qhaw      Qdp     Qlit
  3673 2012-10-23 24.89051 16.67862  8.608321 2.477724 1.432832
  3674 2012-10-24 25.00378 16.48040 11.638224 2.820358 1.393189
  3675 2012-10-25 25.37189 16.99011  7.758816 3.001586 1.322397
  3676 2012-10-26 26.07982 16.87684  6.484558 2.814695 1.279921
  3677 2012-10-27 27.41071 17.07506  4.813864 3.086536 1.228951
  3678 2012-10-28 28.88318 17.16001  5.635052 3.114853 1.220456
  </code></pre>
  <p>I only tried once and this is my code:</p>
  <pre><code>CFbasin %&gt;% filter(month(Date) == 10 &amp; day(Date) &gt;= 4 &amp; day(Date) &lt;= 14) 
  </code></pre>
  <p>this allows me to get all the data within Oct 4 to Oct13 from 2002 to 2012, and then conduct linear regression. But I am not sure how to have it work on the whole dataset and then conduct linear regressions, I am considering <code>for</code> loop and function <code>rollapply()</code>, but really unclear about how to arrange my dataset. Any suggestion and recommendation will be really appreciated, thank you in advance!</p>