[R] intersect() without discarding duplicates?
dwinsemius at comcast.net
Fri May 21 03:01:20 CEST 2010
On May 20, 2010, at 7:30 PM, Nordlund, Dan (DSHS/RDA) wrote:
>> -----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[b %in% a]
>>  2 2 4
>>  2 4
>> The second answer is correct, but I can't predict which variable to
>> 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
He wants this result.
> a <- c(2,4,2,3)
 2 4 2
And this result:
> a <- c(2,4,3)
 2 4
 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
> 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