Say you have

a <- c(1,3,5,7,9)
b <- c(3,6,8,9,10)
c <- c(2,3,4,5,7,9)

A straightforward way to do the job is:

intersect(intersect(a,b),c)

More cleverly, and more conveniently if you have a lot of arguments:

Reduce(intersect, list(a,b,c))

The Reduce function is part of funprog {base}, which includes

Reduce(f, x, init, right = FALSE, accumulate = FALSE)
Filter(f, x)
Find(f, x, right = FALSE, nomatch = NULL)
Map(f, ...)
Negate(f)
Position(f, x, right = FALSE, nomatch = NA_integer_)

The other solution like this

intersectSeveral <- function(...) { Reduce(intersect, list(...)) }
intersectSeveral(a, b, c)

  

intersect for multiple vectors in R的更多相关文章

  1. Hash Table Performance in R: Part I(转)

    What Is It? A hash table, or associative array, is a well known key-value data structure. In R there ...

  2. 碎片︱R语言与深度学习

    笔者:受alphago影响,想看看深度学习,但是其在R语言中的应用包可谓少之又少,更多的是在matlab和python中或者是调用.整理一下目前我看到的R语言的材料: ---------------- ...

  3. R语言实战实现基于用户的简单的推荐系统(数量较少)

    R语言实战实现基于用户的简单的推荐系统(数量较少) a<-c(1,1,1,1,2,2,2,2,3,3,3,4,4,4,5,5,5,5,6,6,7,7) b<-c(1,2,3,4,2,3,4 ...

  4. Discrete.Differential.Geometry-An.Applied.Introduction(sig2013) 笔记

    The author has a course on web: http://brickisland.net/DDGSpring2016/ It has more reading assignment ...

  5. Game Engine Architecture 5

    [Game Engine Architecture 5] 1.Memory Ordering Semantics These mysterious and vexing problems can on ...

  6. [C2P2] Andrew Ng - Machine Learning

    ##Linear Regression with One Variable Linear regression predicts a real-valued output based on an in ...

  7. [线性代数] 线性代数入门A Gentle Introduction

    An Overview: System of Linear Equations Basically, linear algebra solves system of linear equations ...

  8. ButterKnife基本使用

    ButterKnife基本使用 Butter Knife处理字段和方法绑定.   重要更新: 目前(2016.4.29), ButterKnife的最新版本是8.0.1. Demo项目已更新: htt ...

  9. codeforces 341d (树状数组)

    problem Iahub and Xors 题目大意 一个n*n的矩阵,要求支持两种操作. 操作1:将一个子矩阵的所有值异或某个数. 操作2:询问某个子矩阵的所以值的异或和. 解题分析 由于异或的特 ...

随机推荐

  1. 装饰器模式(Decorator)——深入理解与实战应用

    本文为原创博文,转载请注明出处,侵权必究! 1.初识装饰器模式 装饰器模式,顾名思义,就是对已经存在的某些类进行装饰,以此来扩展一些功能.其结构图如下: Component为统一接口,也是装饰类和被装 ...

  2. 使用Maven构建SSH

    本人自己进行的SSH整合,中间遇到不少问题,特此做些总结,仅供参考. 项目环境: struts-2.3.31 + spring-4.3.7 + hibernate-4.2.21 + maven-3.3 ...

  3. Java 工具类—日期获得,随机数,系统命令,数据类型转换

    package tems; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Calendar; ...

  4. Qtp自动测试工具(案例学习)

    ♣Qtp是什么? ♣测试用例网站    ♦注册与登录    ♦测试脚本       ◊录制/执行测试脚本       ◊分析录制的测试脚本       ◊执行.查看测试脚本    ♦建立检查点     ...

  5. Windows7下安装IIS

    1.点击开始→控制面板,然后再点击程序,勿点击卸载程序,否则到不了目标系统界面. 2.然后在程序和功能下面,点击打开和关闭windows功能. 3.进入Windows功能窗口,然后看到internet ...

  6. 【原创】Android 5.0 BLE低功耗蓝牙从设备应用

    如果各位觉得有用,转载+个出处. 现如今安卓的低功耗蓝牙应用十分普遍了,智能手环.手表遍地都是,基本都是利用BLE通信来交互数据.BLE基本在安卓.IOS两大终端设备上都有很好支持,所以有很好发展前景 ...

  7. vsftp使用方法与问题解决

    安装环境 OS:Centos 6.4 vsftp:vsftpd-2.2.2-11.el6_3.1.i686.rpm vsftpd配置文件:/etc/vsftpd/vsftpd.conf 一.      ...

  8. hdu4027线段树

    https://vjudge.net/contest/66989#problem/H 此题真是坑到爆!!说好的四舍五入害我改了一个多小时,不用四舍五入!!有好几个坑点,注意要交换l,r的位置,还有输出 ...

  9. C#基础知识-基本的流程控制语句(三)

    所谓的流程控制就是在程序运行中控制程序的走向,可以通过各种的条件判断执行代码的顺序,有if... if...else.. else...if |switch case...|while... Do.. ...

  10. C#基础知识-编写第一个程序(二)

    通过上一篇数据类型已经介绍了C#中最基本的15种预定义数据类型,了解每一种类型代表的数据以及每种类型的取值范围,这是很重要也是最基本.下面我们通过实例来了解每个类型如何去使用.编写C#程序时我们需要用 ...