title: How to group by every 7 rows, and aggregate those 7 values by median?
body: <p>I have a data frame for daily earning like this:</p>
  
  <pre><code>         date    earning
              1 -40.495074
              2 -88.636625
              3 134.400976
              4  66.325253
              5 -86.337511
              6  -1.266815
              7 267.944212
              8  65.247053
              9  86.177537
             10  64.540579        
  </code></pre>
  
  <p>I want to group every 7 days and aggregate 7 days earning by using median.</p>
  
  <blockquote>
    <p>edit1: It doesn't have to be calendar week, just arbitrary 7 days as as group. </p>
  </blockquote>
  
  <p>So It would be like </p>
  
  <pre><code>week  median-earning
     1  11
     2  22
  </code></pre>
  
  <p>and so on...</p>
  
  <p>How can I achieve this in R?</p>