title: Generate codes based on Nominal Variables present in a dataframe
body: <p>I have a data frame that has 1000 observations and it has this structure below.</p>
  <pre><code>Town &lt;- c(&quot;TownA&quot;, &quot;TownB&quot;, &quot;TownC&quot;,&quot;TownD&quot;,&quot;Town A&quot;, &quot;Town Z&quot;)
  Ward &lt;- c(&quot;Ward B&quot;,&quot;Ward Z&quot;,&quot;Ward A&quot;,&quot;Ward W&quot;,&quot;Ward X&quot;, &quot;Ward &quot;)
  DF &lt;- data.frame(Town, Ward)
  </code></pre>
  <p>I have another dataset that contains codes that represent the nominal observations of Town and Ward. The codes are the ones to be used for analysis. For example, Town A has the code 23, Town B has the code 15, Town Z has the code 7. Instead of manually creating a new column and populating the codes based on towns,  is there a simpler way to do this in R?</p>
  <p>My goal is to mutate a new column that will match the codes with the towns. The dataset has around 200 Towns.</p>