title: cor.test correlation for 2 data frames with p-value in R
body: <p>I have 2 data frames, which are different to each other and I need to do a correlation on those using the <code>cor.test()</code> function in <code>R</code>.</p>
  
  <p>My data frame has the same number of columns but the rows are different to each other. </p>
  
  <p>For instance, after melting (using the <code>melt()</code> function from the <code>reshape</code> package) my data frames look like the following:</p>
  
  <p>Each of these data frames has 84 columns and varying row count: </p>
  
  <pre><code>head(df1)
  
  
  ID  variable    value
  ENSG60  AE02_ID 7.408430
  ENSG53  AE02_ID 0.000000
  ENSG94  AE02_ID 2.556464
  ENSG49  AE02_ID 0.032384
  ENSG9   AE02_ID 0.000000
  </code></pre>
  
  <p>and <code>head(df2)</code>:</p>
  
  <pre><code>ID  variable value
  ENSG3   AE02_ID 0.000001
  ENSG1   AE02_ID 0.329180
  ENSG8   AE02_ID 0.000000
  ENSG10  AE02_ID 29.157761
  ENSG20  AE02_ID 0.633884
  </code></pre>
  
  <p>I used the following <code>R</code> script for my analysis where it returns the Spearman coefficient: </p>
  
  <pre><code>result &lt;- apply(mat1, 2, function(col_mat1){
    apply(mat2, 2, function(col2, col1) {
      cor.test(col2, col1, method = "spearman")$estimate # this returns the p-value of the cor.test
    }, col1=col_mat1)
  })
  </code></pre>
  
  <p>And when I tried to add a p.value to the above function as:</p>
  
  <pre><code>result &lt;- apply(mat1, 2, function(col_mat1){
    apply(mat2, 2, function(col2, col1) {
      cor.test(col2, col1, method = "spearman")cbind($estimate,$p.value) # this returns the p-value of the cor.test
    }, col1=col_mat1)
  })
  </code></pre>
  
  <p>it's returning an error message.</p>
  
  <p>Any suggestions or help would be great. Thank you. The desired out is something like this,</p>
  
  <pre><code>    df1     df2     Coefficient     P.value
      ENSG60  ENSG3   0.1828591281    0.00546547
      ENSG53  ENSG1   0.021038182 0.021038182
      ENSG94  ENSG8   -0.0683044433   0.000657
  </code></pre>