title: aggregating means in a repeating structure in R
body: <p>I have a dataframe like:</p>
  
  <pre><code>p &lt;- c(1,2,3,4,5,6,7,8,9,10)
  </code></pre>
  
  <p>and I want the mean of every two consecutive values:</p>
  
  <p>1+2/2 , 3+4/2 etc.</p>
  
  <p>what I tried is:</p>
  
  <pre><code>agg_data &lt;- aggregate(p, by= list(rep(1:2,5)), FUN= mean)
  </code></pre>
  
  <p>but the result is not what I want. It gives me the mean of every second value:</p>
  
  <p>1+3+5+7+9/5 = 5</p>
  
  <p>2+4+6+8+10/5 = 6</p>
  
  <p>how can I change the function to get the right result?</p>