Re: [R] A %nin% operator?
There's many additional operators defined in the mvbutils package, including %!in%. Kevin On Thu, Aug 5, 2010 at 10:25 AM, David Huffer david.huf...@csosa.govwrote: See Harrell's Hmisc package -- David Huffer, Ph.D. Deputy Director CSOSA/ORE Washington, DC -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ken Williams Sent: Thursday, August 05, 2010 11:20 AM To: r-help@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.willi...@thomsonreuters.com __ R-help@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. __ R-help@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. -- Kevin Wright [[alternative HTML version deleted]] __ R-help@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.
Re: [R] A %nin% operator?
See Harrell's Hmisc package -- David Huffer, Ph.D. Deputy Director CSOSA/ORE Washington, DC -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ken Williams Sent: Thursday, August 05, 2010 11:20 AM To: r-help@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.willi...@thomsonreuters.com __ R-help@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. __ R-help@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.
Re: [R] A %nin% operator?
Just FYI, the Hmisc package has had an implementation of %nin% for some time now. Ken Williams wrote: 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? __ R-help@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.
Re: [R] A %nin% operator?
Ha! Thanks. I should have a closer look at Hmisc in general. -Ken On 8/5/10 10:25 AM, David Huffer david.huf...@csosa.gov wrote: See Harrell's Hmisc package -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ken Williams Sent: Thursday, August 05, 2010 11:20 AM To: r-help@r-project.org Subject: [R] A %nin% operator? [...] So I write a %nin% operator which I define as: `%nin%` - function (x, table) match(x, table, nomatch = 0L) == 0L -- Ken Williams Sr. Research Scientist Thomson Reuters Phone: 651-848-7712 ken.willi...@thomsonreuters.com __ R-help@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.
Re: [R] A %nin% operator?
For curiosity's sake, and perhaps closer in keystrokes to R home, here's another version, `%ni%` - Negate(`%in%`) baptiste On Aug 5, 2010, at 5:30 PM, Ken Williams wrote: Ha! Thanks. I should have a closer look at Hmisc in general. -Ken On 8/5/10 10:25 AM, David Huffer david.huf...@csosa.gov wrote: See Harrell's Hmisc package -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ken Williams Sent: Thursday, August 05, 2010 11:20 AM To: r-help@r-project.org Subject: [R] A %nin% operator? [...] So I write a %nin% operator which I define as: `%nin%` - function (x, table) match(x, table, nomatch = 0L) == 0L -- Ken Williams Sr. Research Scientist Thomson Reuters Phone: 651-848-7712 ken.willi...@thomsonreuters.com __ R-help@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. __ R-help@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.
Re: [R] A %nin% operator?
The examples in the help page for %in% (shared by match) has the definition of a %w/o% binary operator. %w/o% - function(x,y) x[!x %in% y] #-- x without y since: %in% - function(x, table) match(x, table, nomatch = 0) 0 It appears that you have just re-invented the without-wheel. (which also seems to be happening a lot in Formula 1 races lately.) -- David. On Aug 5, 2010, at 11:19 AM, Ken Williams wrote: 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 David Winsemius, MD West Hartford, CT __ R-help@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.
Re: [R] A %nin% operator?
Yeah, and %w/o% seems to have reinvented setdiff(). =) -Ken On 8/5/10 10:53 AM, David Winsemius dwinsem...@comcast.net wrote: The examples in the help page for %in% (shared by match) has the definition of a %w/o% binary operator. %w/o% - function(x,y) x[!x %in% y] #-- x without y since: %in% - function(x, table) match(x, table, nomatch = 0) 0 It appears that you have just re-invented the without-wheel. -- Ken Williams Sr. Research Scientist Thomson Reuters Phone: 651-848-7712 ken.willi...@thomsonreuters.com __ R-help@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.
Re: [R] A %nin% operator?
A related hint, Google doesn't let you search for %nin%, because it ignores % symbols (and most other punctuation), but cuil does allow you to search: http://cuil.com/search?q=%25nin%25+R On 5 August 2010 08:53, David Winsemius dwinsem...@comcast.net wrote: The examples in the help page for %in% (shared by match) has the definition of a %w/o% binary operator. %w/o% - function(x,y) x[!x %in% y] #-- x without y since: %in% - function(x, table) match(x, table, nomatch = 0) 0 It appears that you have just re-invented the without-wheel. (which also seems to be happening a lot in Formula 1 races lately.) -- David. On Aug 5, 2010, at 11:19 AM, Ken Williams wrote: 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 David Winsemius, MD West Hartford, CT __ R-help@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. -- Jeremy Miles Psychology Research Methods Wiki: www.researchmethodsinpsychology.com __ R-help@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.