title: how to efficiently select rows with minimum value in R?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4189807/only-keep-min-value-for-each-factor-level">Only keep min value for each factor level</a>  </p>
  </blockquote>
  
  
  
  <p>Here is my problem, I want to select rows with minimum value in specified column.
  For example:</p>
  
  <pre><code>df &lt;- data.frame(A=c("a","a","b","b"),value=1:4)
  </code></pre>
  
  <p>The result I want is  </p>
  
  <pre><code> A value
   a     1
   b     3
  </code></pre>
  
  <p>I could do with <code>by</code> and <code>ddply</code>, but they are quite slow when df is huge and has many different value in <code>A</code>.</p>
  
  <pre><code>do.call(rbind,by(df,df$A, function(x) x[which.min(abs(x$value)),],simplify=FALSE))
  
  ddply(df, ~A, function(x){x[which.min(abs(x$value)),]})
  </code></pre>
  
  <p>Any suggestions?</p>
  
  <p>Thanks a lot!</p>