title: How to remove rows with a dulicated values in 2 columns but keep a specified row with a certain factor in R
body: <p>I have a data frame of over 200,000 rows but many of these are duplicated IDs with multiple entries. I want to keep just one entry from each ID. If they have any positive status (coded as a factor &quot;positive&quot;) I want to keep just the row with the &quot;positive&quot; and remove the rows with the same ID that say &quot;negative&quot; but if they have multiple negative results I want to keep one row with a &quot;negative&quot; result. Something like this</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ID</th>
  <th>gene</th>
  <th>status</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1001A</td>
  <td>Gene 1</td>
  <td>Negative</td>
  </tr>
  <tr>
  <td>1001A</td>
  <td>Gene 2</td>
  <td>Negative</td>
  </tr>
  <tr>
  <td>1001A</td>
  <td>Gene 1</td>
  <td>Positive</td>
  </tr>
  <tr>
  <td>1001A</td>
  <td>Gene 1</td>
  <td>Negative</td>
  </tr>
  <tr>
  <td>1002B</td>
  <td>Gene 1</td>
  <td>Negative</td>
  </tr>
  <tr>
  <td>1002B</td>
  <td>Gene 1</td>
  <td>Negative</td>
  </tr>
  <tr>
  <td>1002B</td>
  <td>Gene 1</td>
  <td>Negative</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>To this</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ID</th>
  <th>gene</th>
  <th>status</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1001A</td>
  <td>Gene 1</td>
  <td>Positive</td>
  </tr>
  <tr>
  <td>1001A</td>
  <td>Gene 2</td>
  <td>Negative</td>
  </tr>
  <tr>
  <td>1002B</td>
  <td>Gene 1</td>
  <td>Negative</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>But I want this but for 26000 different IDs. Each Id has multiple entries (some have only 1 entry others have between 2-8 entries).</p>
  <pre><code>gene &lt;- c('Gene 1', &quot;Gene 2&quot;, &quot;Gene 1&quot;, &quot;Gene 1&quot;, &quot;Gene 1&quot;, &quot;Gene 1&quot;, &quot;Gene 1&quot;)
  status &lt;- c(&quot;Negative&quot;, &quot;Negative&quot;, &quot;Positive&quot;, &quot;Negative&quot;, &quot;Negative&quot;, &quot;Negative&quot;, &quot;Negative&quot;)
  df &lt;- data.frame(ID, gene, status)
  
   
  
  </code></pre>