[R] intersect() without discarding duplicates?
dwinsemius at comcast.net
Fri May 21 00:10:08 CEST 2010
On May 20, 2010, at 5:58 PM, Jonathan wrote:
> Hi all,
> The ?intersect entry kindly points out that it discards duplicate
> entries. I'm looking, however, to get the intersection while KEEPING
> duplicate entries, and there are no instructions on how to
> accomplish this
> using intersect().
> Does anybody have any idea how this might be done, or am I going to
> need to
> program something from scratch (something like ordering the vectors
> and then
> looping through them)?
>> a <- c(2,4,2,3)
>  2 4
> b %in% a
 FALSE FALSE FALSE TRUE TRUE FALSE TRUE
# Now use logical indexing on "b"
> b[b %in% a]
 2 2 4
> I'd hope the answer to be 2 2 4.
> [[alternative HTML version deleted]]
> 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help