title: Removing duplicates based on a specific category of another column
body: <p>I would like to remove duplicate <code>IDs</code> in my data using the <code>Category</code> columns. A subset of my data is as follows:</p>
  <pre><code>df &lt;- data.frame(ID=c(1,2,3,4,1,4,2),
                   category=c(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;,&quot;b&quot;,&quot;a&quot;,&quot;a&quot;))
  df
  
    ID category
  1  1        a
  2  2        b
  3  3        c
  4  4        d
  5  1        b
  6  4        a
  7  2        a
  
  </code></pre>
  <p>If there is a duplicated <code>ID</code> from <code>Category b</code> , I need to keep it and remove the corresponding ID from other categories. And, I have no priority if the duplicated <code>IDs</code> are form other categories excluding <code>Category b</code>. So, my favorite outcome is:</p>
  <pre><code>  ID category
  1  2        b
  2  3        c
  3  4        d
  4  1        b
  </code></pre>
  <p>I have already read this post : <a href="https://stackoverflow.com/questions/47539860/r-remove-duplicates-from-a-dataframe-based-on-categories-in-a-column/47540016">R: Remove duplicates from a dataframe based on categories in a column</a>
  but can't find my answer</p>