title: Loop over subsets of data in dataframe
body: <p>I have a dataframe that looks like this:</p>
  
  <pre><code>id &lt;- c(1,1,1,2,2,2,3,3,3,4,4,4)
  value &lt;- c(2,3,3,4,2,2,4,4,3,2,2,3)
  df &lt;- data.frame(id, value)
  </code></pre>
  
  <p>What i would like to do now is compile two data-frames of the first ids (1 and 2) and compile a calculation on it. The I want to move on the next two data-frames (with id 3 and 4) and perform a calculation on it etc...And this for all rows. So the psuedo code looks like:</p>
  
  <pre><code>#loop over dataframe
   for i in 1:nrow(df) {
  
    #fetch the rows of the first two ids
    #perform calculcation on ti
    #move on to the next two columns
    #perform calculation on it.
  
  }
  </code></pre>
  
  <p>Any clues on how I can code this most effecient in R?</p>