[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() .

Cheers,
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
intersect(x,z)

cu
	Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
 
 and
 
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
http://mips.gsf.de/staff/pagel

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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