如何从多个向量中找到共同元素? [英] How to find common elements from multiple vectors?

查看:34
本文介绍了如何从多个向量中找到共同元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何从多个向量中找到共同元素?

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))

这篇关于如何从多个向量中找到共同元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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