title: R data frame group by a column and create repetition number of another column
body: <p>I have a data frame like this:</p>
  
  <pre><code>ii &lt;- data.frame(cid = c(rep('a',8),rep('b',5)),
                   Interaction = c(rep('VCS',3), c('SLS'), rep('TCU',2), rep('MFM',2), rep('SLS', 2), 'COMM', rep('MFM',2)),
                   stringsAsFactors = F
  )
  
     cid Interaction
  1    a         VCS
  2    a         VCS
  3    a         VCS
  4    a         SLS
  5    a         TCU
  6    a         TCU
  7    a         MFM
  8    a         MFM
  9    b         SLS
  10   b         SLS
  11   b        COMM
  12   b         MFM
  13   b         MFM
  </code></pre>
  
  <p>And I would like to first group by <code>cid</code> then create another column that shows repetition number of <code>Interaction</code> columns. The result should look like this:</p>
  
  <pre><code>   cid Interaction   replicate
  1    a         VCS   1
  2    a         VCS   2
  3    a         VCS   3
  4    a         SLS   1
  5    a         TCU   1
  6    a         TCU   2
  7    a         MFM   1
  8    a         MFM   2
  9    b         SLS   1
  10   b         SLS   2
  11   b        COMM   1
  12   b         MFM   1
  13   b         MFM   2
  </code></pre>
  
  <p>Eventually I wanted to also reshape this to a wide format (couldn't do it with the current format cause I lose duplicates) that would resemble something like:</p>
  
  <pre><code>   cid         InteractionTuple   
  1    a         VCS1;VCS2;VCS3;SLS1;TCU1;TCU2;MFM1;MFM2
  2    b         SLS1;SLS2;COMM;MFM1;MFM2
  </code></pre>
  
  <p>to be able to run association rule mining techniques, that are currently supporting repeated items per transaction. </p>