否定R中的%in% [英] Negation of %in% in R
问题描述
R中是否像!%in%
或%!in%
那样对%in%
作了短的求反?
Is there a short negation of %in%
in R like !%in%
or %!in%
?
我当然可以用!(c("A", "B") %in% c("B", "C"))
取反c("A", "B") %in% c("B", "C")
(请参阅此问题),但是我希望采用一种更直接的方法,并保留一对方括号(就像大多数人更喜欢c("A", "B") != c("B", "C")
而不是!(c("A", "B") == c("B", "C"))
一样.)
Of course I can negate c("A", "B") %in% c("B", "C")
by !(c("A", "B") %in% c("B", "C"))
(cf. this question) but I would prefere a more straight forward approach and save a pair of brackets (alike presumably most people would prefer c("A", "B") != c("B", "C")
over !(c("A", "B") == c("B", "C"))
).
推荐答案
不,没有内置函数可以执行此操作,但是您可以使用
No, there isn't a built in function to do that, but you could easily code it yourself with
`%nin%` = Negate(`%in%`)
或
`%!in%` = Negate(`%in%`)
请参阅此线程和后续讨论:%in%运算符-NOT IN
还指出,软件包Hmisc
包含运算符%nin%
,因此,如果您将其用于应用程序,则该软件包已经存在.
Also, it was pointed out the package Hmisc
includes the operator %nin%
, so if you're using it for your applications it's already there.
library(Hmisc)
"A" %nin% "B"
#[1] TRUE
"A" %nin% "A"
#FALSE
这篇关于否定R中的%in%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!