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

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Thu Oct 25 16:17:44 CEST 2018


Hello,

2. x[!x$A %in% y$B, ]

1.
An Introduction to R, file R-into.pdf in your docs folder.
http://www.cookbook-r.com/Basics/Indexing_into_a_data_structure/


Hope this helps,

Rui Barradas

Às 15:06 de 25/10/2018, Knut Krueger escreveu:
> Hi Bert,
> another question for indexing
> 1. is there a good manual  for indexing
> 
> 2.  is it possible to get !%in%
> f.e
> 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.




More information about the R-help mailing list