title: How to Use Tidyverse to Remove Select Duplicate Values Based on the Value of Another Column
body: <pre><code>library(tidyverse)
  </code></pre>
  
  <p>Using the example data at the bottom, I'm trying to remove duplicates in the ID column, but only the duplicates where the "Year" column equals 2017. </p>
  
  <p>I tried the code below, which doesn't seem to work.</p>
  
  <pre><code>DF &lt;- DF %&gt;% 
    group_by(ID) %&gt;% 
    mutate(REMOVE = if_else(duplicated(ID) &amp; Year == 2017, 1, 0))
  
  DF &lt;- DF %&gt;% 
    group_by(ID) %&gt;% 
    mutate(REMOVE = if_else(!unique(ID) &amp; Year == 2017, 1, 0))
  </code></pre>
  
  <p>I'm trying to use the code to group by "ID", then use an "if_else" statement to code year 2017 within each group of duplicate ID's with a 1. I'll then remove all the 1's with the filter code below. </p>
  
  <pre><code>DF &lt;- DF %&gt;%
    filter(REMOVE == 1)
  </code></pre>
  
  <p>I'm not sure why this code isn't working. I've also tried changing the column types for ID and Year from character, numeric, etc, but this didn't help. </p>
  
  <p>Help would be appreciated! </p>
  
  <pre><code>ID&lt;-c(18998878,8888888,57485746,18998878,45454536,64536475,64536475,87966666,58675844,58695847,68574443,87966666)
  Program&lt;-c("A111","B488","T687","A111","G888","T444","T444","P867","R444","B323","F888","P867")
  Code&lt;-c(1222,4534,543,1222,4678,6544,6544,9898,8888,5656,6666,9898)
  Year&lt;-c(2016,2016,2017,2017,2017,2017,2016,2016,2016,2017,2017,2017)
  DF&lt;-data_frame(ID,Program,Code,Year)
  </code></pre>