correlation table with number of observations N
<p>I can get a correlation matrix with <code>cor()</code> but I do no know how to get the underlying number of observations. Is there a way? </p>

<pre><code>#reproducible data
mydata &lt;- mtcars
#add random missing
set.seed(17)
mydata[sample(x=nrow(mydata), size=5), "mpg"] &lt;- NA
mydata[sample(x=nrow(mydata), size=5), "hp"] &lt;- NA
mydata[sample(x=nrow(mydata), size=5), "wt"] &lt;- NA
View(mydata)


#correlation matrix
cor(subset(mydata, select=c(mpg, hp, wt)), use="pairwise.complete.obs")
</code></pre>

<p>I would like a matrix, parallel to the correlation matrix, with these three values: </p>

<pre><code>#N observations
cor.test(mydata$mpg, mydata$hp, na.action="na.exclude")$parameter + 2
cor.test(mydata$mpg, mydata$wt, na.action="na.omit")$parameter + 2
cor.test(mydata$wt, mydata$hp, na.action="na.omit")$parameter + 2
#or
nrow(na.omit(subset(mydata, select=c(mpg, hp))))
nrow(na.omit(subset(mydata, select=c(mpg, wt))))
nrow(na.omit(subset(mydata, select=c(hp, wt))))
</code></pre>