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


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:

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 ...


1 Answer 1


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


gives me

[1] "na.omit"


Syntax of cor is different from that of cor.test. Use

cor(a, d, use="pairwise.complete.obs")

to get a meaningful value

  • $\begingroup$ gives me the same thing ! but, when I apply na.omit, in the normal "cor(a,d, na.action=T)" still complains. $\endgroup$
    – Areza
    Sep 28, 2015 at 8:53
  • 1
    $\begingroup$ Use cor(a, d, use="pairwise.complete.obs") $\endgroup$
    – lanenok
    Sep 28, 2015 at 12:56
  • $\begingroup$ Thanks ! and sorry for asking this again, does it mean, cor.test automatically omit NA and calculate the p-value based on left over ? $\endgroup$
    – Areza
    Sep 28, 2015 at 21:41
  • $\begingroup$ Yes. This is the default behaviour. $\endgroup$
    – lanenok
    Sep 29, 2015 at 15:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.