title: Choosing a single row based on multiple criteria
body: <p>Can anyone think how to how to do this in R? </p>
  
  <p><strong>Simple data:</strong> </p>
  
  <pre><code>    seq&lt;-c("A","A","A","B","B","B","B")
      rank&lt;-c(1,2,3,1,2,3,4)
      match&lt;-c("y","n","y","n","n","y","y")
      df&lt;- as.data.frame(cbind(seq,rank,match))
  
        seq rank match
      1   A    1     y
      2   A    2     n
      3   A    3     y
      4   B    1     n
      5   B    2     n
      6   B    3     y
      7   B    4     y
  </code></pre>
  
  <p>I want to create a <code>‘choose’</code> column whereby, for every unique seq, the first instance of <code>y</code> under <code>match</code> is given a <code>T</code>, and all the rest are given a <code>F</code>. </p>
  
  <p>The desired output would be: </p>
  
  <pre><code>      seq rank match choose
      1   A    1     y      T
      2   A    2     n      F
      3   A    3     y      F
      4   B    1     n      F
      5   B    2     n      F
      6   B    3     y      T
      7   B    4     y      F
  </code></pre>
  
  <p>It’s easy enough to return the correct value for rank 1 and 2 by combining an <code>ifelse</code> statement with lag, however I'm stumped once rank <code>&gt;2</code>. </p>
  
  <p>The real <code>dataset</code> contains<code>+100k rows</code>, and rank could go up to the hundreds, so I don’t want to just extend an <code>ifelse</code> statement to check values above using lag. </p>
  
  <p>My ultimate aim is to create a new <code>dataset</code> from all of the T's under "choose", so if someone know how to directly pull them out without creating a new column that would be even better! </p>
  
  <p>I’m guessing an <code>ifelse</code> statement is a daft way of doing this, but I’m stuck :/ </p>
  
  <p>Any help would be much appreciated : )</p>