[R] "logical indexing, " [was] match() question or needle haystack problem for a data.frame

Fox, John j|ox @end|ng |rom mcm@@ter@c@
Fri Oct 26 14:25:48 CEST 2018


Dear Knut,

> -----Original Message-----
> From: R-help [mailto:r-help-bounces using r-project.org] On Behalf Of Knut
> Krueger
> Sent: Friday, October 26, 2018 2:29 AM
> To: r-help mailing list <r-help using r-project.org>
> Subject: Re: [R] "logical indexing, " [was] match() question or needle haystack
> problem for a data.frame
> 
> Am 25.10.18 um 16:13 schrieb peter dalgaard:
> >
> >
> > Yes: x[!(x$A %in% y$B),]
> 
> Ok thats in my opinion a little workaround

Not a work-around but a solution. That is, one can't expect to find an existing function for every problem.

> why?:
> 
> There is an
> = and !=

Actually == and !=

> < and >
> 
> 
> means the opposite is available between terms.
> 
> why is there f.e no %!in%, %notin%  or !%in%
> 
> This would be more intuitive.

If you feel strongly about this, it's not hard to supply it:

> `%!in%` <- function(x, y) !(x %in% y)
> (1:4) %in% (2*1:4)
[1] FALSE  TRUE FALSE  TRUE
> (1:4) %!in% (2*1:4)
[1]  TRUE FALSE  TRUE FALSE

Best,
 John

-----------------------------------------------------------------
John Fox
Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
Web: https://socialsciences.mcmaster.ca/jfox/


> 
> Kind regards Knut
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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