[R] Getting indeices of intersecting elements.
wdunlap at tibco.com
Wed Oct 14 19:28:09 CEST 2009
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Praveen Surendran
> Sent: Wednesday, October 14, 2009 9:15 AM
> To: r-help at r-project.org
> Subject: [R] Getting indeices of intersecting elements.
> Is there a command to get the indices of intersecting elements of two
> vectors as intersect() will give the elements and not its indices.
intersect() uses match() to do that.
match(x,y,nomatch) gives the indices of elements of y that
elements of x match and match(y,x,nomatch) gives
the indices of the elements of x that elements of
y match. In each case, the unmatched elements
are marked by the value in nomatch. E.g.
 "a" "b" "c" "d" "e"
 "b" "d" "f" "h" "j"
> match(y,x,nomatch=0) # x[c(2,4)] are in y
 2 4 0 0 0
> match(x,y,nomatch=0) # y[c(1,2)] are in x
 0 1 0 2 0
(If the second argument contains duplicates the index
is for the first of them.)
Spotfire, TIBCO Software
> Thanks in advance.
> Praveen Surendran
> School of Medicine and Medical Sciences
> University College Dublin
> Belfield, Dublin 4
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help