title: How to extract the p.value and estimate from cor.test() in a data.frame?
body: <p>In this example, I have temperatures values from 50 different sites, and I would like to correlate the Site1 with all the 50 sites. But I want to extract only the components <strong><em>"p.value"</em></strong> and <strong><em>"estimate"</em></strong> generated with the function <strong>cor.test()</strong> in a data.frame into two different columns.  </p>
  
  <p>I have done my attempt and it works, but I don't know how!
  For that reason I would like to know how can I simplify my code, because the problem is that I have to run two times a Loop "for" to get my results.</p>
  
  <p>Here is my example:</p>
  
  <pre><code># Temperature data
   data &lt;- matrix(rnorm(500, 10:30, sd=5), nrow = 100, ncol = 50, byrow = TRUE,
                 dimnames = list(c(paste("Year", 1:100)),
                                 c(paste("Site", 1:50))) )
  # Empty data.frame
   df &lt;- data.frame(label=paste("Site", 1:50), Estimate="", P.value="")
  
  # Extraction
  for (i in 1:50) {
   df1 &lt;- cor.test(data[,1], data[,i] )
   df[,2:3] &lt;- df1[c("estimate", "p.value")]
     }
  
  for (i in 1:50) {
    df1 &lt;- cor.test(data[,1], data[,i] )
   df[i,2:3] &lt;- df1[c("estimate", "p.value")]
     }
  
   df
  </code></pre>
  
  <p>I will appreciate very much your help :)</p>