title: Assign unique value for duplicated rows
body: <p>I want to assign the value for each duplicated row by ID in R</p>
  
  <pre><code>df &lt;- data.frame(ID=c(1,1,1,2,2,2,2,2,3,3,4),
              Code = c("A","A","A","B","B","C","C","D","A","A","C"))
  &gt; df
     ID Code
  1   1    A
  2   1    A
  3   1    A
  4   2    B
  5   2    B
  6   2    C
  7   2    C
  8   2    D
  9   3    A
  10  3    A
  11  4    C
  </code></pre>
  
  <p>I want the output like this,check duplicated by ID, then assign the second duplicate _1 and so on...</p>
  
  <pre><code>   ID Code Code_n
  1   1    A      A
  2   1    A    A_1
  3   1    A    A_2
  4   2    B      B
  5   2    B    B_1
  6   2    C      C
  7   2    C    C_1
  8   2    D      D
  9   3    A      A
  10  3    A    A_1
  11  4    C      C
  </code></pre>