title: How to replace repeating entries in a data frame with n-(number of times it's repeated) in R?
body: <p>In my data I have repeating entries in a column. What I'm trying to do is if an entry <em>n</em> is repeated more than 2 times within a column, then I want to replace that entry with <em><code>n-(number_of_times_it_has_repeated - 2)</code></em>. For example, if my data looks like this:</p>
  <pre><code>  df &lt;- data.frame(
    A = c(1,2,2,4,5,7,7,7,7,2,8,8),
    B = c(2,3,4,5,6,7,8,9,10,11,12,13)
  )
  &gt; df
  A  B
  1  2
  2  3
  2  4
  4  5
  5  6
  7  7
  7  8
  7  9
  7 10
  2 11
  8 12
  8 13
  </code></pre>
  <p>we can see that in <code>df$A</code> 7 is repeated 4 times. If the entry is repeated more than 2 times, then I want to replace that entry. So in my example,the 1st and 2nd entry of the number 7 would remain unchanged. The 3rd instance of the number 7 would be replaced by : <em>7 - (3-2)</em>. The 4th instance of number 7 would be replaced by <em>7 - (4-2)</em>.</p>
  <p>We can also see that in <code>df$A</code>, the number 2 is repeated 3 times. using the same method, the 3rd instance of number 2 would be replaced with <em>2 - (3-2)</em>.</p>
  <p>As there are no repeating values in <code>df$B</code>, that column would remain unchanged.</p>
  <p>For clarity, my expected result would be:</p>
  <pre><code>dfNew &lt;- data.frame(
    A = c(1,2,2,4,5,7,7,6,5,1,8,8),
    B = c(2,3,4,5,6,7,8,9,10,11,12,13)
  )
  &gt; dfNew
  A  B
  1  2
  2  3
  2  4
  4  5
  5  6
  7  7
  7  8
  6  9
  5 10
  1 11
  8 12
  8 13
  </code></pre>