title: Collapsing data frame by selecting one row per group
body: <p>I'm trying to collapse a data frame by removing all but one row from each group of rows with identical values in a particular column. In other words, the first row from each group.</p>
  
  <p>For example, I'd like to convert this</p>
  
  <pre><code>&gt; d = data.frame(x=c(1,1,2,4),y=c(10,11,12,13),z=c(20,19,18,17))
  &gt; d
    x  y  z
  1 1 10 20
  2 1 11 19
  3 2 12 18
  4 4 13 17
  </code></pre>
  
  <p>Into this:</p>
  
  <pre><code>    x  y  z
  1   1 11 19
  2   2 12 18
  3   4 13 17
  </code></pre>
  
  <p>I'm using aggregate to do this currently, but the performance is unacceptable with more data:</p>
  
  <pre><code>&gt; d.ordered = d[order(-d$y),]
  &gt; aggregate(d.ordered,by=list(key=d.ordered$x),FUN=function(x){x[1]})
  </code></pre>
  
  <p>I've tried split/unsplit with the same function argument as here, but unsplit complains about duplicate row numbers.</p>
  
  <p>Is rle a possibility? Is there an R idiom to convert rle's length vector into the indices of the rows that start each run, which I can then use to pluck those rows out of the data frame?</p>