title: "Correlation & Significance if more than 30 pairs" using R and ddply
body: <p>Part of the solution to my problem I found here: <a href="https://stackoverflow.com/questions/6760284/how-to-calculate-correlation-in-r">How to calculate correlation In R</a></p>
  
  <pre><code>set.seed(123)
  X &lt;- data.frame(ID = rep(1:2, each=5), a = sample(1:10), b = sample(1:10))
  ddply(X, .(ID), summarize, cor_a_b = cor(a,b))
  </code></pre>
  
  <p>In addition to <code>cor</code> (which calculates Pearsons r) I calculate <code>cor.test</code> (for the p-value). But this fails in case of "not enough finite observations", so when some IDs are solo, which they are quite often in my case.</p>
  
  <p>So I need to calculate r only if there are more than 30 or so pairs of data, if there are less I want NA.</p>
  
  <p>Second problem is that the verbose output of <code>cor.test</code> inflates the resulting data frame - even if the only thing I wanted is the p-value. That is, if p actually is, what I understand it to be. Is it the significance of r?</p>
  
  <p>I only know the t-test, to calculate the significance of r.</p>
  
  <p>{Formula of the t-test-value: <code>t = (r·(n-2)^0.5)/(1-r^2)^0.5)</code> - but t is not the significance yet, otherwise I would try to implement the formula into the <code>ddply</code> statement}</p>