这很简单,但我似乎找不到它.我知道R有一个否定的版本%in%返回"不在." 显然我可以使用!(x %in% y),但语言包含一个已经否定的构造,我想使用它,goshdarnit.
那么功能是什么?搜索以及%nin%和%notin%所有的失败.
如果您!(x %in% y)使用以下示例数据对您的答案进行基准测试,则可以为您提供奖励互联网:
x <- sample( sample(letters,5), 10^3, replace=TRUE)
y <- sample( letters, 10^5, replace=TRUE)
Run Code Online (Sandbox Code Playgroud)
shh*_*its 14
只是出于兴趣.定义
"%w/o%" <- function(x, y) x[!x %in% y]
'%ni%' <- Negate('%in%')
> benchmark(y[y%ni%x], y%w/o%x,replications=1000)
test replications elapsed relative user.self sys.self user.child
2 y %w/o% x 1000 5.32 1.000000 4.60 0.70 NA
1 y[y %ni% x] 1000 5.34 1.003759 4.68 0.65 NA
sys.child
2 NA
1 NA
Run Code Online (Sandbox Code Playgroud)
我有饼干吗?