title: Recode a string column into integer using dplyr
body: <p>How to create a new integer column <code>recode</code> which recodes for an existing column <code>y</code> in the dataframe <code>df</code> using <code>dplyr</code> approaches?</p>
  
  <pre><code># Generates Random data 
  df &lt;- data.frame(x = sample(1:100, 50), 
                   y = sample(LETTERS, 50, replace = TRUE), 
                   stringsAsFactors = FALSE)
  # Structure of the data
  str(df)
  # 'data.frame': 50 obs. of  2 variables:
  #   $ x: int  90 4 33 85 30 19 78 77 7 10 ...
  # $ y: chr  "N" "B" "P" "W" ...
  
  # Making the character vector as factor variable
  df$y &lt;- factor(df$y)
  
  # Structure of the data to llok at the effect of factor creation
  str(df)
  # 'data.frame': 50 obs. of  2 variables:
  #   $ x: int  90 4 33 85 30 19 78 77 7 10 ...
  # $ y: Factor w/ 23 levels "A","B","C","E",..: 12 2 14 21 12 22 7 1 6 17 ...
  
  # collecting the levels of the factor variable
  labs &lt;- levels(df$y)
  
  # Recode the levels to sequential integers
  recode &lt;- 1:length(labs)
  
  # Creates the recode dataframe
  dfrecode &lt;- data.frame(labs, recode)
  
  # Mapping the recodes to the original data
  df$recode &lt;- dfrecode[match(df$y, dfrecode$labs), 'recode']
  </code></pre>
  
  <p>This code works as expected. But I want to replace this approach with a dplyr or other efficient approaches. I can achieve the same using <a href="https://stackoverflow.com/q/46527758/4836511">this approach</a> if I know all the values. But I would like to do this without seeing or explicitly listing the values present in the column </p>