title: Replace factors with a numeric value
body: <p>I have a data frame where each column is of type factor and has over 3000levels.
  Is there a way where I can replace each level with a numeric value.
  Consider the inbuilt data frame InsectSprays</p>
  
  <pre><code>&gt; str(InsectSprays)
  'data.frame':   72 obs. of  2 variables:
   $ count: num  10 7 20 14 14 12 10 23 17 20 ...
   $ spray: Factor w/ 6 levels "A","B","C","D",..: 1 1 1 1 1 1 1 1 1 1 ...
  </code></pre>
  
  <p>The replacement should be as follows:</p>
  
  <p>A=1,B=2,C=3,D=4,E=5,F=6.</p>
  
  <p>If there are 3000 levels:</p>
  
  <p>"USA"=1,"UK"=2....,France="3000".</p>
  
  <p>The solution should automatically detect the levels(Ex: 3000),then replace each level starting from 1 to 3000.</p>