title: How to make an index variable in R
body: <p>How to make an index variable based on the number levels of a factor variable? Explicitly:  </p>
  
  <pre><code>x=c(rep(letters[1:5], 3))
  x=sort(x)
  index=c(rep(1:3, 5))
  data.frame(cbind(x,index))
  
     x index
  1  a 1
  2  a 2
  3  a 3
  4  b 1
  5  b 2
  6  b 3
  7  c 1
  8  c 2
  9  c 3
  10 d 1
  11 d 2
  12 d 3
  13 e 1
  14 e 2
  15 e 3
  </code></pre>
  
  <p>I want to create index variable, in the above, for a large data.</p>