[R] intersect() without discarding duplicates?
Nordlund, Dan (DSHS/RDA)
NordlDJ at dshs.wa.gov
Fri May 21 01:30:53 CEST 2010
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Jonathan
> Sent: Thursday, May 20, 2010 3:25 PM
> To: David Winsemius
> Cc: r-help
> Subject: Re: [R] intersect() without discarding duplicates?
> Thanks, but that doesn't quite work, since I'd want the result of b[b
> a] to be symmetric with a[a%in%b] (so if there are two 2's in EACH
> I'll get two 2's in the result, but if there are two 2's in only one
> but one two in the other, the result will show only one 2.
> > a <- c(2,4,3)
> > b<-c(6,6,5,2,2,8,4)
> > b[b %in% a]
>  2 2 4
> > a[a%in%b]
>  2 4
> The second answer is correct, but I can't predict which variable to put
> which position in the statement, so I'd need them both to be correct.
I think you have misread the intersect documentation. Given your examples above intersect is what you in fact want.
> a <- c(2,4,3)
 2 4
Hope this is helpful,
Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204
More information about the R-help