James Holland
2012-May-11 13:50 UTC
[R] Matching - finding and listing data that is one object but not in another
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. Michael Weylandt <michael.weylandt@gmail.com>
2012-May-11 19:23 UTC
[R] Matching - finding and listing data that is one object but not in another
? 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.