与 %in% 相反:排除具有向量中指定值的行 [英] Opposite of %in%: exclude rows with values specified in a vector
本文介绍了与 %in% 相反:排除具有向量中指定值的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数据框 D1 中的分类变量 V1 可以具有由字母 A 到 Z 表示的值.我想创建一个子集 D2,它排除了一些值,例如 B、N 和 T.基本上,我想要一个与 %in%
A categorical variable V1 in a data frame D1 can have values represented by the letters from A to Z. I want to create a subset D2, which excludes some values, say, B, N and T. Basically, I want a command which is the opposite of %in%
D2 = subset(D1, V1 %in% c("B", "N", "T"))
推荐答案
您可以使用 !
运算符基本上使任何 TRUE FALSE 和每个 FALSE TRUE.所以:
You can use the !
operator to basically make any TRUE FALSE and every FALSE TRUE. so:
D2 = subset(D1, !(V1 %in% c('B','N','T')))
你也可以自己创建一个操作符:
You can also make an operator yourself:
'%!in%' <- function(x,y)!('%in%'(x,y))
c(1,3,11)%!in%1:10
[1] FALSE FALSE TRUE
这篇关于与 %in% 相反:排除具有向量中指定值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文