[R] A kind of set operation in R

Dirk Eddelbuettel edd at debian.org
Fri Apr 6 00:07:57 CEST 2012


Julio,

Nobody mentioned the _set_ operations union(), intersect(), setdiff(),
which are described under 'help(union)' (and the other names, of course)

  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



More information about the R-help mailing list