title: Group the values for a certain time interval and calculate the means
body: <p>I am studying data of soil respiration (CO2 flux) over the time. The soil respiration is measured automatically every 10 minutes. </p>
  
  <p>My dataset contains the following colums : </p>
  
  <blockquote>
    <ul>
    <li>Year</li>
    <li>Day </li>
    <li>Hours</li>
    <li>Minutes</li>
    <li>Time in decimal units (Day + Hours/24 + Minutes/(24*60)</li>
    <li>Soil respiration</li>
    </ul>
  </blockquote>
  
  <p>The soil respiration is measured every 10 mins, so I have 144 values per day. 
  For a specific analysis, I need to have the means of the values each 3 hours for each day. </p>
  
  <blockquote>
    <ul>
    <li>0h : 1 value at 00:00 the first day and then mean of the values between 21:10 and 00:00</li>
    <li>3h (mean of 0:10, 0:20, 0:30, 0:40, 0:50, 1:0, 1:10, 1:20, [...] 2:50; 3:00) mean of 18 values. </li>
    <li>6h (mean of the values between 3:10 and 6:00)</li>
    <li>12h (mean of the values between 6:10 and 12:00)</li>
    <li>15h (mean of the values between 12:10 and 15:00)</li>
    <li>18h (mean of the values between 15:10 and 18:00)</li>
    <li>21h (mean of the values between 18:10 and 21:00) </li>
    <li>00h (mean of the values between 21:10 and 00:00)</li>
    </ul>
  </blockquote>
  
  <p>etc... 
  So for each day I would like to obtain 8 values of soil respiration and each value is a mean value of 18 values. </p>
  
  <p>How could I program this with R ? 
  I have really big dataset, so I can't do it manually for each day. </p>
  
  <p>Example of the dataset : </p>
  
  <pre><code>Year =c(2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014,2014)
  Day= c(274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274,274)
  Hours= c(0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3)
  Minutes = c(0,10,20,30,40,50,0,10,20,30,40,50,0,10,20,30,40,50,0,10,20,30,40,50) 
  Time_Dec=c(274.000,274.007,274.014,274.021,274.028,274.035,274.042,274.049,274.056,274.063,274.069,274.076,274.083,274.090,274.097,274.104,274.111,274.118,274.125,274.132,274.139,274.146,274.153,274.160)
  Flux=c(0.84,0.88,0.91,0.95,0.98,1.02,0.84,0.87,0.91,0.94,0.98,1.01,0.83,0.87,0.90,0.94,0.97,1.01,0.83,0.87,0.90,0.94,0.97,1.00)
  </code></pre>
  
  <p>So, I would like to keep the first value and then have the mean for the 18th following values (until <code>Time_Dec= 274.125</code>)</p>