title: How to generate a new numeric column to represent a sequence of characters in R?
body: <p>The data I have is like sdf:</p>
  
  <pre><code>s = c("aa", "bb", "cc","cc","cc","cc","aa", "bb", "cc", "bb", "bb", "bb", "bb")
  sdf = data.frame(s)
  </code></pre>
  
  <p>What I want to do is generate a column that goes from 1 to whatever, but for every repeated character the number doesn't change. I can get a sequence with the following:</p>
  
  <pre><code>sdf$wrongseq&lt;-seq(1:nrow(sdf))
  </code></pre>
  
  <p>But how do I get the sequence like the description above:</p>
  
  <pre><code>rightseq&lt;- c(1, 2, 3,3,3,3,4,5, 6, 7, 7, 7, 7)
  sdf = cbind(sdf,rightseq)
  </code></pre>