# cor.test in R and na values [closed]

I wonder how cor.test is dealing with NA values.

I have

a =  c(1.1, 1.0, 1.2, 1.0, 0.9)
b = 2*a
d = b
d[3] = NA

cor(a, d) = NA


but

cor.test(a, d) =
Pearson's product-moment correlation

data:  a and d
t = 94906000, df = 2, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
1 1
sample estimates:
cor
1


I guess cor.test is excluding NA and calculating the correlation on the rest. But I am not fully sure. Also, I am not sure, if it consider the same in p-value too or not ? I could not figure out the default setting either ...

As you can read in the cor.test documetation,

na.action: a function which indicates what should happen when the data contain NAs. Defaults to getOption("na.action").

Checking the default setting (in the command line) with

getOption("na.action")


gives me

[1] "na.omit"


Syntax of cor is different from that of cor.test. Use
cor(a, d, use="pairwise.complete.obs")

• Use cor(a, d, use="pairwise.complete.obs") Sep 28, 2015 at 12:56