function to find common rows between more than two data frames in R

Posted by biohazard on Stack Overflow See other posts from Stack Overflow or by biohazard
Published on 2013-06-28T08:45:21Z Indexed on 2013/06/28 10:21 UTC
Read the original article Hit count: 249

Filed under:
|
|
|

I have 4 data frames, and would like to find the rows whose values in a certain column do not exist in any of the other data frames. I wrote this function:

#function to test presence of $Name in 3 other datasets
common <- function(a, b, c, d) {
  is.B <- is.numeric(a$Name %in% b$Name) == 1
  is.C <- is.numeric(a$Name %in% c$Name) == 1
  is.D <- is.numeric(a$Name %in% d$Name) == 1
  t <- as.numeric(is.B & is.C & is.D)
  t
}

However, the output is always t = 0. This means that it tells me that there are no unique rows in any data sets, even though the datas frames have very different numbers of rows. Since there are no duplicate rows in any of the data frames, I should be getting t = 1 for at least some rows in the biggest dataset. Can someone figure out what I got wrong?

© Stack Overflow or respective owner

Related posts about r

    Related posts about data.frame