title: Add column to df that's the output of a function that uses different column values combined to be a vector input
body: <p>This is a very simplified version of my actual problem.   </p>
  
  <p>My real <code>df</code> has many columns and I need to perform this action using a <code>select</code> from a character vector of column names.  </p>
  
  <pre><code>library(tidyverse)
  
  
  df &lt;- data.frame(a1 = c(1:5), 
               b1 = c(3,1,3,4,6), 
               c1 = c(10:14), 
               a2 = c(9:13), 
               b2 = c(3:7), 
               c2 = c(15:19))
  df
    a1 b1 c1 a2 b2 c2
  1  1  3 10  9  3 15
  2  2  1 11 10  4 16
  3  3  3 12 11  5 17
  4  4  4 13 12  6 18
  5  5  6 14 13  7 19
  </code></pre>
  
  <p>Let's say I wanted to get the <code>cor</code> for each row for selected columns using <code>mutate</code> - I tried:</p>
  
  <pre><code>df %&gt;% 
    mutate(my_cor = cor(x = c(a1,b1,c2), y = c(a2,b2,c2)))
  </code></pre>
  
  <p>but this doesn't work as it uses the full column of data for each column header input.  </p>
  
  <p>The first row of the <code>my_cor</code> column of the output <code>df</code> from above should be the calculation:</p>
  
  <p><code>cor(x = c(1,3,10), y = c(9,3,15))</code></p>
  
  <p>And the next row should be:</p>
  
  <p><code>cor(x = c(2,1,11), y = c(10,4,16))</code></p>
  
  <p>and so on.  The actual function I'm using is more complex but it does take two vector inputs like <code>cor</code> does so I figured this would be a good proxy.</p>
  
  <p>I have a feeling I should be using <code>purrr</code> for this action (<a href="https://stackoverflow.com/questions/49816669/how-to-use-map-from-purrr-with-dplyrmutate-to-create-multiple-new-columns-base">similar to this post</a>) but I haven't gotten it to work.  </p>
  
  <p>Bonus: The <em>actual</em> problem I'm facing is using a function that would use many different columns so I'd like to be able <code>select</code> them from a a character vector like <code>my_list_of_cols &lt;- c("a1", "b1", "c1")</code> (my true list is much longer). </p>
  
  <p>I suspect I'd be using <code>pmap_dbl</code> like the post I linked to but I can't get it to work - I tried something like...</p>
  
  <pre><code>mutate(my col = pmap_dbl(select(., var = my_list_of_cols), somefunction))
  </code></pre>
  
  <p>(note that <code>somefunction</code> in the above portion takes a 2 vector inputs but one of them is static and pre-defined - you can assume the vector <code>c(a2, b2, c2)</code> is the static and predefined one like: </p>
  
  <pre><code>somefunction &lt;- function(a1,b1,c1){
      a2 = 1 
      b2 = 4
      c2 = 5
      my_vec = c(a2, b2, c2)
           cor(x = (a1,b1,c1), y = my_vec)
  }
  </code></pre>
  
  <p>)</p>
  
  <p>I'm still learning how to use <code>purrr</code> so any help would be greatly appreciated!</p>