title: Data dictionary linking in R
body: <p>I have two dataframes as below.</p>
  <ul>
  <li>I wanted to update the <code>patients</code> dataframe</li>
  <li>and swap the <code>Option_name</code> with <code>Option_num</code> for all.</li>
  </ul>
  <pre class="lang-r prettyprint-override"><code>## dataframe
  patid = c(1, 2, 3, 4, 5, 6, 7, 8, 9) 
  technique = c(&quot;VMAT&quot;, &quot;IMRT&quot;, &quot;ELEC&quot;, &quot;VMAT&quot;, &quot;VMAT&quot;, &quot;VMAT&quot;, &quot;ELEC&quot;, &quot;VMAT&quot;, &quot;IMRT&quot;)
  intent = c(&quot;Radical&quot;, &quot;Curative&quot;, &quot;Adjuvant&quot;, &quot;Curative&quot;, &quot;Curative&quot;, &quot;Curative&quot;, &quot;Curative&quot;, &quot;Curative&quot;, &quot;Adjuvant&quot;)
  patients = data.frame(patid, technique, intent)
  </code></pre>
  <pre class="lang-r prettyprint-override"><code>## data dictionary
  variable = c(&quot;technique&quot;, &quot;technique&quot;, &quot;technique&quot;, &quot;intent&quot;, &quot;intent&quot;, &quot;intent&quot;)
  Option_name = c(&quot;VMAT&quot;, &quot;IMRT&quot;, &quot;ELEC&quot;, &quot;Radical&quot;, &quot;Curative&quot;, &quot;Adjuvant&quot;)
  Option_num = c(1, 2, 3, 1, 2, 3)
  dict = data.frame(variable, Option_name, Option_num)
  </code></pre>
  <p>So the the <code>patients</code> dataframe would change<br />
  FROM<br />
  <a href="https://i.stack.imgur.com/fSBEg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fSBEg.png" alt="from" /></a></p>
  <p>TO<br />
  <a href="https://i.stack.imgur.com/EZsN2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EZsN2.png" alt="to" /></a></p>
  <p>I know how to do this via a very manual process:</p>
  <pre class="lang-r prettyprint-override"><code>patients$technique &lt;- replace(as.character(patients$technique), patients$technique == &quot;VMAT&quot;,1)
  </code></pre>
  <p>But I am sure there is a more efficient way of doing this.</p>
  <p>Any help would be greatly appreciated!</p>