Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有三个向量(a、b 和 c),并使用
common<-Reduce(intersect,list(a,b,c))
我现在想知道哪些元素是 a 独有的。我不能使用a[!(a%in%common)],因为这可能会返回一个和另一个向量中的元素。
a[!(a%in%common)]
我不认为这是一个新的或独特的问题,但我在寻找答案时遇到的部分问题是我不确定该a[!(a%in%common)]函数被称为什么。
您可以reduce对任意长度的列表使用和 setdiff
reduce
Reduce(setdiff, list(a,b,c))
简单的解决方案是a[!(a %in% union(b,c))].
a[!(a %in% union(b,c))]
setdiff(a, union(b,c) ) # .....
当然取决于“独特于a”的含义对你和我来说是否相同,但对我来说它与a[!(a%in%common)].