当使用函数plicated()时,对于重复的NA值返回FALSE [英] Return FALSE for duplicated NA values when using the function duplicated()

查看:99
本文介绍了当使用函数plicated()时,对于重复的NA值返回FALSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道为什么重复项会表现出与NA相同的方式:

just wondering why duplicated behaves the way it does with NAs:

> duplicated(c(NA,NA,NA,1,2,2))
[1] FALSE  TRUE  TRUE FALSE FALSE  TRUE

实际上

> NA == NA
[1] NA

有没有办法像这样将重复的标记NA标记为假?

is there a way to achieve that duplicated marks NAs as false, like this?

> duplicated(c(NA,NA,NA,1,2,2))
[1] FALSE  FALSE  FALSE FALSE FALSE  TRUE

推荐答案

对于函数duplicated,您可以像这样使用参数incomparables:

You use the argument incomparables for the function duplicated like this :

> duplicated(c(NA,NA,NA,1,2,2))
[1] FALSE  TRUE  TRUE FALSE FALSE  TRUE
> duplicated(c(NA,NA,NA,1,2,2),incomparables=NA)
[1] FALSE FALSE FALSE FALSE FALSE  TRUE

它确定无法比较的值(在这种情况下为NA),并为这些值返回FALSE.另请参见?duplicated

It determines the values that cannot be compared (in this case NA) and returns FALSE for those values. See also ?duplicated

这篇关于当使用函数plicated()时,对于重复的NA值返回FALSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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