title: Row-wise cor() on subset of columns using dplyr::mutate()
body: <pre><code>set.seed(8)
  df &lt;- data.frame(
    A=sample(c(1:3), 10, replace=T), 
    B=sample(c(1:3), 10, replace=T),
    C=sample(c(1:3), 10, replace=T),
    D=sample(c(1:3), 10, replace=T),
    E=sample(c(1:3), 10, replace=T), 
    F=sample(c(1:3), 10, replace=T))
  </code></pre>
  
  <p>Would like to pass a subset of columns into a dplyr <code>mutate()</code> and make a row-wise calculation, for instance <code>cor()</code> to get correlation between column A-C and D-F, but cannot figure out how. Found SO inspiration <a href="https://stackoverflow.com/questions/28159143/add-column-with-row-wise-mean-over-selected-columns-using-dplyr">here</a>, <a href="https://stackoverflow.com/questions/21818181/applying-a-function-to-every-row-of-a-table-using-dplyr">here</a> and <a href="https://stackoverflow.com/questions/28751023/performing-dplyr-mutate-on-subset-of-columns">here</a>, but nevertheless failed to produce an acceptable code. For instance, I tried this:</p>
  
  <pre><code>require(plyr)
  require(dplyr)
  df %&gt;%
    rowwise() %&gt;%
    mutate(c=cor(.[[1:3]],.[[4:6]]))
  </code></pre>