title: select unique combinations of some columns in R, and random value for another column
body: <p>Suppose I have a data frame, myD, with the following columns: x, y, a, b.</p>
  
  <p>I want to select unique combinations of x and y. That part is easy, just use unique on the first two columns. However, for each unique combination of x,y there are multiple values of a and b; I want to select a random row. I.e., among all of the rows that match a particular combination of x,y, I simply want to randomly select just one of the rows. Note that I don't want to independently sample a and b; they should come from the same row.</p>
  
  <p>I was using ddply to do this:</p>
  
  <pre><code>ddply(myD, c("x","y"), summarize,
          a=a[1],
          b=b[1])
  </code></pre>
  
  <p>This of course gets the first pair of a,b for each combination of x,y; I was randomly permuting the entire data frame to achieve uniformity.</p>
  
  <p>Anyway, this ddply command is extremely slow when the data frame has a million rows or more. Is there a faster way to do this?</p>