title: dplyr filter: Get rows with minimum of variable, but only the first if multiple minima
body: <p>I want to make a grouped filter using <code>dplyr</code>, in a way that within each group only that row is returned which has the minimum value of variable <code>x</code>.</p>
  
  <p>My problem is: As expected, in the case of multiple minima <em>all</em> rows with the minimum value are returned. But in my case, <strong>I only want the first row</strong> if multiple minima are present.</p>
  
  <p>Here's an example:</p>
  
  <pre><code>df &lt;- data.frame(
  A=c("A", "A", "A", "B", "B", "B", "C", "C", "C"),
  x=c(1, 1, 2, 2, 3, 4, 5, 5, 5),
  y=rnorm(9)
  )
  
  library(dplyr)
  df.g &lt;- group_by(df, A)
  filter(df.g, x == min(x))
  </code></pre>
  
  <p>As expected, all minima are returned:</p>
  
  <pre><code>Source: local data frame [6 x 3]
  Groups: A
  
    A x           y
  1 A 1 -1.04584335
  2 A 1  0.97949399
  3 B 2  0.79600971
  4 C 5 -0.08655151
  5 C 5  0.16649962
  6 C 5 -0.05948012
  </code></pre>
  
  <p>With ddply, I would have approach the task that way:</p>
  
  <pre><code>library(plyr)
  ddply(df, .(A), function(z) {
      z[z$x == min(z$x), ][1, ]
  })
  </code></pre>
  
  <p>... which works:</p>
  
  <pre><code>  A x           y
  1 A 1 -1.04584335
  2 B 2  0.79600971
  3 C 5 -0.08655151
  </code></pre>
  
  <p><strong>Q: Is there a way to approach this in dplyr?</strong> (For speed reasons)</p>