title: Dplyr get paired columns (foo.x, foo.y) difference
body: <p>I want to get the difference of many <code>foo.x</code> and <code>foo.y</code> columns all in one mutate across. Here is an example dataframe.</p>
  <pre><code>mydf &lt;- tibble(ID = 1:5,
                 foo1.x = c(9, 8, 3, 2, 10),
                 foo1.y = c(4, 5, 3, 2, 4),
                 foo2.x = c(8, 5,10, 11, 6),
                 foo2.y = c(10, 6,4, 8, 5),
                 foo3.x = c(15, 12, 5, 45, 1),
                 foo3.y = c(5, 8, 2, 6, 4))
  </code></pre>
  <p>I want to do <code>foo.x - foo.y</code> like the code below, but get <code>non-numeric argument to binary operator</code> error although the columns are all of type num in <code>str(df)</code></p>
  <pre><code>df &lt;- mydf %&gt;%        
    mutate(across(ends_with('.x'), ~. -~eval(
     as.name(paste0(substring(toString(cur_column()),1,
      str_length(toString(cur_column()))-2),&quot;.y&quot;)))))
  </code></pre>
  <p>Thanks</p>