[R] Matching - finding and listing data that is one object but not in another

R. Michael Weylandt <michael.weylandt@gmail.com> michael.weylandt at gmail.com
Fri May 11 21:23:35 CEST 2012


? setdiff

Michael

On May 11, 2012, at 8:50 AM, James Holland <holland.aggie at gmail.com> wrote:

> What is the best way to find out what elements/numbers that are in one
> object are not in another.
> 
> 
> I came up with this method, but I'm wondering if there is a more efficient
> way (and one that doesn't seem so "clunky").
> 
> #Example
> 
> id <- c(1,2,3,4,5,6,7,9,10)
> 
> example.1 <- data.frame(id)
> 
> #Second object, this time with an 8 in it.
> 
> id <- c(1,2,3,4,5,6,7,8,9,10)
> 
> example.2 <- data.frame(id)
> 
> finder <- example.2$id %in% example.1$id
> 
> example.2 <- cbind(example.2,finder)
> 
> missing.list <- subset(example.2, test2==F)
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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