title: Group data by group of days within months in R
body: <p>I am trying to summarise this daily time serie of rainfall by groups of 10-day periods within each month and calculate the acummulated rainfall. </p>
  
  <pre><code>library(tidyverse)
  (dat &lt;- tibble(
    date = seq(as.Date("2016-01-01"), as.Date("2016-12-31"), by=1),
    rainfall = rgamma(length(date), shape=2, scale=2)))
  </code></pre>
  
  <p>Therefore, I will obtain variability in the third group along the year, for instance: in january the third period has 11 days, february 9 days, and so on. This is my try: </p>
  
  <pre><code>library(lubridate)
  dat %&gt;% 
    group_by(decade=floor_date(date, "10 days")) %&gt;%
    summarize(acum_rainfall=sum(rainfall), 
              days = n())
  </code></pre>
  
  <p>this is the resulting output</p>
  
  <pre><code># A tibble: 43 x 3
     decade     acum_rainfall  days
     &lt;date&gt;             &lt;dbl&gt; &lt;int&gt;
   1 2016-01-01         48.5     10
   2 2016-01-11         39.9     10
   3 2016-01-21         36.1     10
   4 2016-01-31          1.87     1
   5 2016-02-01         50.6     10
   6 2016-02-11         32.1     10
   7 2016-02-21         22.1      9
   8 2016-03-01         45.9     10
   9 2016-03-11         30.0     10
  10 2016-03-21         42.4     10
  # ... with 33 more rows
  </code></pre>
  
  <p>can someone help me to sum the residuals periods to the third one to obtain always 3 periods within each month? This would be the desired output (pay attention to the row 3):</p>
  
  <pre><code>   decade     acum_rainfall  days
     &lt;date&gt;             &lt;dbl&gt; &lt;int&gt;
   1 2016-01-01         48.5     10
   2 2016-01-11         39.9     10
   3 2016-01-21         37.97    11
   4 2016-02-01         50.6     10
   5 2016-02-11         32.1     10
   6 2016-02-21         22.1      9
  </code></pre>