title: select rows with largest value of variable within a group in r
body: <pre><code>a.2&lt;-sample(1:10,100,replace=T)
  b.2&lt;-sample(1:100,100,replace=T)
  a.3&lt;-data.frame(a.2,b.2)
  
  r&lt;-sapply(split(a.3,a.2),function(x) which.max(x$b.2))
  
  a.3[r,]
  </code></pre>
  
  <p>returns the list index, not the index for the entire data.frame</p>
  
  <p>Im trying to return the largest value of <code>b.2</code> for each subgroup of <code>a.2</code>. How can I do this efficiently?</p>