title: How to automatically adjust R script based on # of variables (var1, var2, etc.)
body: <p>Main dataset:</p>
  
  <pre><code>df &lt;- data.frame(var1 =c(1, 2, 1), var2 = c(2, 3, 3))
  </code></pre>
  
  <p>My mapping table:</p>
  
  <pre><code>mt &lt;- data.frame(var1 = c(1, 2, 1), var2 = c(2, 3,3), color = c('red', 'blue', 'yellow'))
  </code></pre>
  
  <p>To merge df to mt, preserving all rows in df:</p>
  
  <pre><code>df &lt;- merge(x = df, y=mt, by=c("var1", "var2"), all.x = TRUE)
  </code></pre>
  
  <p>QUESTION: How can I dynamically change the code so that if I have 4 number of vars (ie. var1, var2, var3, var4), the code will automatically get adjusted to the following?</p>
  
  <p><code>df &lt;- merge(x = df, y=mt, by=c("var1", "var2", "var3", "var4"), all.x = TRUE)</code></p>
  
  <p>Similarly, if we have 5 number of vars, it will be automatically get adjusted to:</p>
  
  <p><code>df &lt;- merge(x = df, y=mt, by=c("var1", "var2", "var3", "var4", "var5"), all.x = TRUE)</code></p>