NA values ​​are not excluded in `cor`

To simplify, I have a dataset that looks like this:

b <- 1:6 # > b # [1] 1 2 3 4 5 6 jnk <- c(2, 4, 5, NA, 7, 9) # > jnk # [1] 2 4 5 NA 7 9 

When I try:

 cor(b, jnk, na.rm=TRUE) 

I get:

 > cor(b, jnk, na.rm=T) Error in cor(b, jnk, na.rm = T) : unused argument (na.rm = T) 

I also tried na.action = na.exclude etc. No, it seems to work. It would be very helpful to know what the problem is and how I can fix it. Thanks.

+5
source share
2 answers

Read ?cor :

 cor(x, y = NULL, use = "everything", method = c("pearson", "kendall", "spearman")) 

He has no na.rm , he has use .

optional character string giving a method for calculating covariances in the absence of missing values. This should be (abbreviation) one of the lines "everything" , "all.obs" , "complete.obs" , "na.or.complete" or "pairwise.complete.obs" .

Choose one. Detailed information on what each of them does is in the Details ?cor section.

+20
source

Just to make sure the answer to this question is clear.

To ignore NA, use

 b <- 1:6 jnk <- c(2, 4, 5, NA, 7, 9) cor(b, jnk, use="complete.obs") [1] 0.9905977 
+1
source

All Articles