title: R - How to use dplyr left_join by column index?
body: <p>How to use column index to <code>dplyr::left_join</code> (and your family)?</p>
  <p>Example (by column names):</p>
  <pre><code>    library(dplyr)
      data1 &lt;- data.frame(var1 = c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;), var2 = c(&quot;d&quot;, &quot;d&quot;, &quot;f&quot;)) 
      data2 = data.frame(alpha = c(&quot;d&quot;, &quot;f&quot;), beta = c(20, 30))
      left_join(data1, data2, by = c(&quot;var2&quot; = &quot;alpha&quot;))
  </code></pre>
  <p>However, replacing <code>by = c(&quot;var2&quot; = &quot;alpha&quot;))</code> to <code>by = c(data1[,2] = data2[,1])</code> results to this error:</p>
  <blockquote>
  <p><code>by</code> must be a (named) character vector, list, or NULL for natural
  joins (not recommended in production code), not logical.</p>
  </blockquote>
  <p>I need to use the &quot;column position&quot; for loop on new functions.
  How can I do it?</p>