How do you find the sample sizes used in calculations on r?

robert wilson picture robert wilson · Jan 1, 2013 · Viewed 18.4k times · Source

I am running correlations between variables, some of which have missing data, so the sample size for each correlation are likely different. I tried print and summary, but neither of these shows me how big my n is for each correlation. This is a fairly simple problem that I cannot find the answer to anywhere.

Answer

user1317221_G picture user1317221_G · Jan 2, 2013

like this..?

x <- c(1:100,NA)
length(x)
length(x[!is.na(x)])

you can also get the degrees of freedom like this...

y <- c(1:100,NA)
x <- c(1:100,NA)

cor.test(x,y)$parameter

But I think it would be best if you show the code for how your are estimating the correlation for exact help.