与%in%相反:排除在向量中指定值的行 [英] Opposite of %in%: exclude rows with values specified in a vector

查看:87
本文介绍了与%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屋!

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