[R] A kind of set operation in R
Bert Gunter
gunter.berton at gene.com
Fri Apr 6 00:42:32 CEST 2012
On Thu, Apr 5, 2012 at 3:07 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
>
> Julio,
>
> Nobody mentioned the _set_ operations union(), intersect(), setdiff(),
> which are described under 'help(union)' (and the other names, of course)
... but which are basically wrappers for match().
-- Bert
>
> R> X <- c(10:13, 17,18)
> R> Y <- c(11,12,17,18)
> R> intersect(X, Y) # gives the actual values
> [1] 11 12 17 18
> R> X %in% intersect(X, Y) # use %in% to map to bool as desired
> [1] FALSE TRUE TRUE FALSE TRUE TRUE
> R>
>
> Oh, and no need to reply on-list to thousands of list subscribers if you
> found this helpful. These one-line 'thanks' message are not that universally
> useful, even though they are very polite :)
>
> Dirk
>
> --
> R/Finance 2012 Conference on May 11 and 12, 2012 at UIC in Chicago, IL
> See agenda, registration details and more at http://www.RinFinance.com
>
> ______________________________________________
> 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.
--
Bert Gunter
Genentech Nonclinical Biostatistics
Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
More information about the R-help
mailing list