查找两个向量之间不重叠的元素

问题描述:

我正在尝试识别未包含在其他向量中的元素.例如在两个向量中我有

I'm trying to identify elements which are not included in the other vector. For instance in two vectors I have

list.a <- c("James", "Mary", "Jack", "Sonia", "Michelle", "Vincent")

list.b <- c("James", "Sonia", "Vincent")

有没有办法验证哪些人没有重叠?在示例中,我想要获得包含 Mary、Jack 和 Michelle 的向量结果.

is there a way to verify which people do not overlap? In the example, I would want to get the vector result that contains Mary, Jack, and Michelle.

任何建议都会有所帮助!

Any suggestions will help!

是的,有办法:

setdiff(list.a, list.b)
# [1] "Mary"     "Jack"     "Michelle"