title: replace and remove duplicate rows using ifelse
body: <p>I have a data frame of postcodes with a regional/metro classification assigned. In some instances, due to the datasource, the same postcode will occur with both a regional and metro classification.</p>
  <pre class="lang-r prettyprint-override"><code>  POSTCODE   REGON  
  1     3000    METRO       
  2     3000    REGIONAL      
  3     3256    METRO     
  4     3145    METRO     
  </code></pre>
  <p>I am wondering how to remove the duplicate row and replace the region with &quot;SPLIT&quot; in these instances.</p>
  <p>I have tried using the below code however this reassignes the entire dataset with either &quot;METRO&quot; or &quot;REGIONAL&quot;</p>
  <pre class="lang-r prettyprint-override"><code>test &lt;- within(PC_ACTM, REGION &lt;- ifelse(duplicated(&quot;Postcode&quot;), &quot;SPLIT&quot;, REGION))
  </code></pre>
  <p>The desired output would be</p>
  <pre class="lang-r prettyprint-override"><code>  POSTCODE   REGON  
  1     3000    SPLIT
  2     3256    METRO     
  3     3145    METRO
  </code></pre>
  <p>Example data:</p>
  <pre><code>dput(PC_ACTM)
  structure(list(POSTCODE = c(3000L, 3000L, 3256L, 3145L), REGON = c(&quot;METRO&quot;, 
  &quot;REGIONAL&quot;, &quot;METRO&quot;, &quot;METRO&quot;)), class = &quot;data.frame&quot;, row.names = c(&quot;1&quot;, 
  &quot;2&quot;, &quot;3&quot;, &quot;4&quot;))
  </code></pre>