NA值未排除在`cor`中 [英] NA values not being excluded in `cor`

查看:209
本文介绍了NA值未排除在`cor`中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为简化起见,我有一个数据集,如下所示:

To simplify, I have a data set which is as follows:

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

当我尝试时:

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

我得到:

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

我也尝试过na.action = na.exclude等.似乎没有任何作用.知道问题是什么以及我如何解决它会非常有帮助.谢谢.

I've also tried na.action = na.exclude, etc. None seem to work. It'd be really helpful to know what the issue is and how I can fix it. Thanks.

推荐答案

TL; DR:改用:

cor(b, jnk, use="complete.obs")


阅读?cor:

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

它没有na.rm,它具有use.

一个可选的字符串,提供了一种在缺少值的情况下计算协方差的方法.这必须是字符串"everything""all.obs""complete.obs""na.or.complete""pairwise.complete.obs"中的一个(缩写).

an optional character string giving a method for computing covariances in the presence of missing values. This must be (an abbreviation of) one of the strings "everything", "all.obs", "complete.obs", "na.or.complete", or "pairwise.complete.obs".

选择一个.有关每个操作的详细信息,请参见?corDetails部分.

Pick one. Details of what each does is in the Details section of ?cor.

这篇关于NA值未排除在`cor`中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆