s-news
[Top] [All Lists]

Re: Compare two vectors without a loop

To: yiwu ye <yiwu21111958@yahoo.com>
Subject: Re: Compare two vectors without a loop
From: Sundar Dorai-Raj <sundar.dorai-raj@pdf.com>
Date: Fri, 27 Jun 2003 08:33:36 -0500
Cc: s-news@lists.biostat.wustl.edu
Organization: PDF Solutions, Inc.
References: <20030627022121.57421.qmail@web13302.mail.yahoo.com>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01


yiwu ye wrote:
Dear list members,
suppose I have:
x y
1 3
2 4
3 5
4 6
5 6
I want to make a comparison between x and y, and to produce a new vector like
z
T
T
T
F
F
so, I can know the first three elements of y, 3,4,5,can find the same value in x.
Could someone told how I can do it without a loop, please? Many thanks.
Yiwu


In S-PLUS 6.1 just use the %in% operator:

z <- y %in% x

In older versions of S-PLUS, library(hmisc) has the %in% operator or just use ?match.

Regards,
Sundar


<Prev in Thread] Current Thread [Next in Thread>