本文介绍了如何从多个向量中找到共同的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能告诉我如何从多个向量中找到共同的元素?
Can anyone tell me how to find the common elements from multiple vectors?
a <- c(1,3,5,7,9)
b <- c(3,6,8,9,10)
c <- c(2,3,4,5,7,9)
我想从上述向量(例如3和9)中获得公共元素
I want to get the common elements from the above vectors (ex: 3 and 9)
推荐答案
也许有更聪明的方法解决这个问题,但是
There might be a cleverer way to go about this, but
intersect(intersect(a,b),c)
会做.
如果您有很多争论,请更聪明,更方便:
More cleverly, and more conveniently if you have a lot of arguments:
Reduce(intersect, list(a,b,c))
这篇关于如何从多个向量中找到共同的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!