[R] A %nin% operator?
David Huffer
David.Huffer at csosa.gov
Thu Aug 5 17:25:00 CEST 2010
See Harrell's Hmisc package
--
David Huffer, Ph.D.
Deputy Director
CSOSA/ORE
Washington, DC
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Ken Williams
Sent: Thursday, August 05, 2010 11:20 AM
To: r-help at r-project.org
Subject: [R] A %nin% operator?
Sometimes I write code like this:
> qf.a <- subset(qf, pubid %in% c(104, 106, 107, 108)) qf.b <-
> subset(qf, !pubid %in% c(104, 106, 107, 108))
and I get a little worried that maybe I've remembered the precedence
rules wrong, so I change it to
> qf.a <- subset(qf, pubid %in% c(104, 106, 107, 108)) qf.b <-
> subset(qf, !(pubid %in% c(104, 106, 107, 108)))
and pretty soon my code looks like fingernail clippings (or Lisp) and
I'm thinking about precedence rather than my original task. So I write
a %nin% operator which I define as:
> `%nin%` <- function (x, table) match(x, table, nomatch = 0L) == 0L
and then I'm happy again.
I wonder, would something like this find a home in core R? Or is that
too much syntactic sugar for your taste?
--
Ken Williams
Sr. Research Scientist
Thomson Reuters
Phone: 651-848-7712
ken.williams at thomsonreuters.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.
More information about the R-help
mailing list