title: Select row by level of a factor
body: <p>I have a data frame, <code>df2</code>,  containing observations grouped by a ID <code>factor</code> that I would like to subset. I have used another function to identify which rows <em>within each factor group</em> that I want to select. This is shown below in <code>df</code>:</p>
  
  <pre><code>df &lt;- data.frame(ID = c("A","B","C"),
                   pos = c(1,3,2))
  df2 &lt;- data.frame(ID = c(rep("A",5), rep("B",5), rep("C",5)),
                    obs = c(1:15))
  </code></pre>
  
  <p>In <code>df</code>, <code>pos</code> corresponds to the index of the row that I want to select within the factor level mentioned in <code>ID</code>, not in the whole dataframe <code>df2</code>.I'm looking for a way to select the rows for each <code>ID</code> according to the right index (so their row number within the level of each factor of <code>df2</code>).</p>
  
  <p>So, in this example, I want to select the first value in <code>df2</code> with <code>ID == 'A'</code>, the third value in <code>df2</code> with <code>ID == 'B'</code> and the second value in <code>df2</code> with <code>ID == 'C'</code>.</p>
  
  <p>This would then give me:</p>
  
  <pre><code>df3 &lt;- data.frame(ID = c("A", "B", "C"),
                    obs = c(1, 8, 12))
  </code></pre>