title: Running several correlations simultaneously in R
body: <p>I am trying to run several correlations in R by adapting code I have used to do this for regressions. </p>
  
  <p>This is the existing code that I have used successfully for regressions. </p>
  
  <pre><code>combineddvs &lt;- colnames(dfc[,87:100])
  form &lt;- paste("yourbehavior_c ~ days + days2 +", combineddvs)
  models &lt;- form %&gt;%
    set_names(combineddvs) %&gt;%
    map(~lm(.x, data = dfc))
  map(models, summary)
  </code></pre>
  
  <p>This is my adaptation of it for the correlations I'd like to run. </p>
  
  <pre><code>combineddvs &lt;- c("committed", "goodfaith", "strongfeel")
  form &lt;- paste("df$main, df$", combineddvs)
  models &lt;- form %&gt;%
    set_names(combineddvs) %&gt;%
    map(~cor(.x))
  map(models, summary)
  </code></pre>
  
  <p>The first two lines work, but I get this error when trying to create the object "models": </p>
  
  <pre><code>Error in cor(.x) : supply both 'x' and 'y' or a matrix-like 'x'
  </code></pre>
  
  <p>I know that I need both an x and a y to run a correlation. However, I am trying to include both of these in the "form" object. </p>
  
  <p>This is a clunky way of showing what I am trying to do. I have more than 3 items, so this is not efficient in practice. </p>
  
  <pre><code>cor(df$main, df$committed)
  cor(df$main, df$goodfaith)
  cor(df$main, df$strongfeel)
  </code></pre>
  
  <p>How can I do this? I am open to modifying the above code or to using an entirely different approach. </p>