[R] meaning of asymmetric on help page for intersect

Duncan Murdoch murdoch at stats.uwo.ca
Tue Jan 13 17:01:37 CET 2009


On 1/13/2009 10:41 AM, Juliet Hannah wrote:
> Sorry if this is a silly question. What does asymmetric refer to from
> ?intersect, and are there any
> aspects of the result that may be different from expected (reason for
> exclamation point) ?

There are two definitions for a set difference:  the symmetric one and 
the asymmetric one.

R uses the asymmetric one, so setdiff(A, B) is the intersection of A 
with the complement of B.  (The complement is taken in the union of A 
and B).

The symmetric difference is described on the Wikipedia page 
http://en.wikipedia.org/wiki/Symmetric_difference.  In R, you could get 
it as

union(setdiff(A, B), setdiff(B, A))

Duncan Murdoch

> 
> As toy data, if needed, here are the examples from the help page.
> 
> (x <- c(sort(sample(1:20, 9)),NA))
> (y <- c(sort(sample(3:23, 7)),NA))
> 
> Thanks,
> 
> Juliet
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list