[R] Is variable in one vector part of variable in another

Bert Gunter gunter.berton at gene.com
Mon Jun 2 17:38:35 CEST 2008

Indeed, but note that both %in% and intersect() are essentially wrappers for
match() .

Bert Gunter

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Philipp Pagel
Sent: Saturday, May 31, 2008 2:27 PM
To: r-help at r-project.org
Subject: Re: [R] Is variable in one vector part of variable in another

> I have 2 vectors x & z
> x  has 10 variables in it
> z has 75 variable in it
> I need to check all 75 variables in z and see if they are present in the
> vector x.

In addition to the solution using %in% which has already been suggested,
you may also want to play with something like this:

# make up some data
x = sample(1:8, 10, rep=T)
z = sample(1:25, 75, rep=T)
# find intersection between x and z


Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
Institut für Bioinformatik und Systembiologie / MIPS
Helmholtz Zentrum München -
Deutsches Forschungszentrum für Gesundheit und Umwelt
Ingolstädter Landstrasse 1
85764 Neuherberg, Germany

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list