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

peter dalgaard pd@|gd @end|ng |rom gm@||@com
Thu Oct 25 16:13:54 CEST 2018



> On 25 Oct 2018, at 16:06 , Knut Krueger <rhelp using krueger-family.de> wrote:
> 
> Hi Bert,
> another question for indexing
> 1. is there a good manual  for indexing

?Extract is at least authoritative....

> 
> 2.  is it possible to get !%in%
> f.e


Yes: x[!(x$A %in% y$B),]

-pd

> x =data.frame("A"=c(1:5),"C"=c("A","B","C","D","E"))
> y =data.frame("B"=c(1,3,5))
> test = x[x$A %in% y$B,]
> test = x[x$A %in% y$B,]
> 
> test
> A C
> 1 1 A
> 3 3 C
> 5 5 E
> 
> 
> means: the result where I am looking for is:
> test
> A C
> 2 2 B
> 4 4 D
> 
> no problem with a loop but in a short way I do not find a solution
> 
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk  Priv: PDalgd using gmail.com




More information about the R-help mailing list