intersect for multiple vectors in R
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的更多相关文章
- 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 ...
- 碎片︱R语言与深度学习
笔者:受alphago影响,想看看深度学习,但是其在R语言中的应用包可谓少之又少,更多的是在matlab和python中或者是调用.整理一下目前我看到的R语言的材料: ---------------- ...
- 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 ...
- Discrete.Differential.Geometry-An.Applied.Introduction(sig2013) 笔记
The author has a course on web: http://brickisland.net/DDGSpring2016/ It has more reading assignment ...
- Game Engine Architecture 5
[Game Engine Architecture 5] 1.Memory Ordering Semantics These mysterious and vexing problems can on ...
- [C2P2] Andrew Ng - Machine Learning
##Linear Regression with One Variable Linear regression predicts a real-valued output based on an in ...
- [线性代数] 线性代数入门A Gentle Introduction
An Overview: System of Linear Equations Basically, linear algebra solves system of linear equations ...
- ButterKnife基本使用
ButterKnife基本使用 Butter Knife处理字段和方法绑定. 重要更新: 目前(2016.4.29), ButterKnife的最新版本是8.0.1. Demo项目已更新: htt ...
- codeforces 341d (树状数组)
problem Iahub and Xors 题目大意 一个n*n的矩阵,要求支持两种操作. 操作1:将一个子矩阵的所有值异或某个数. 操作2:询问某个子矩阵的所以值的异或和. 解题分析 由于异或的特 ...
随机推荐
- swust oj(0088)表达式的转换
表达式的转换(0088) Time limit(ms): 5000 Memory limit(kb): 65535 Submission: 435 Accepted: 93 Accepted 16级卓 ...
- MySQL 5.7贴心参数之 log_timestamps
写在前面 使用 MySQL 的过程中,经常会有人碰到这么一个问题,看错误日志.慢查询日志的时候,时间总是和本地时间对不上,差了 8 个小时,这样分析起来就相对麻烦了一些. 新改进 对于不知道是什么原因 ...
- Linux - 函数的栈帧
栈帧(stack frame),机器用栈来传递过程参数,存储返回信息,保存寄存器用于以后恢复,以及本地存储.为单个过程(函数调用)分配的那部分栈称为栈帧.栈帧其实是两个指针寄存器, 寄存器%ebp为帧 ...
- Nodejs进阶:MD5入门介绍及crypto模块的应用
本文摘录自<Nodejs学习笔记>,更多章节及更新,请访问 github主页地址.欢迎加群交流,群号 197339705. 简介 MD5(Message-Digest Algorithm) ...
- C#总结(二)事件Event 介绍总结
最近在总结一些基础的东西,主要是学起来很难懂,但是在日常又有可能会经常用到的东西.前面介绍了 C# 的 AutoResetEvent的使用介绍, 这次介绍事件(event). 事件(event),对于 ...
- Express - 入门
Express入门篇 1.HelloWorld 根目录新建server.js文件,插入代码: var express = require('express'); var app = express( ...
- 【算法系列学习】[kuangbin带你飞]专题十二 基础DP1 E - Super Jumping! Jumping! Jumping!
https://vjudge.net/contest/68966#problem/E http://blog.csdn.net/to_be_better/article/details/5056334 ...
- poj3160强连通分量加dfs
After retirement as contestant from WHU ACM Team, flymouse volunteered to do the odds and ends such ...
- windows下配置mysql数据库主从
所用到工具: Mysql.Navicat Premium: 主库设置: 一.设置my.ini 文件: 1.在安装目录下找到my.ini 文件: 默认路径:C:\Program Files\MySQL\ ...
- JavaEE开发之SpringBoot整合MyBatis以及Thymeleaf模板引擎
上篇博客我们聊了<JavaEE开发之SpringBoot工程的创建.运行与配置>,从上篇博客的内容我们不难看出SpringBoot的便捷.本篇博客我们继续在上篇博客的基础上来看一下Spri ...