[英]function to find common rows between more than two data frames in R
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. 我有4个数据框,并且想查找在任何其他数据框中都不存在某个列中的值的行。 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. 但是,输出始终为t =0。这意味着它告诉我,即使数据帧具有非常不同的行数,任何数据集中也没有唯一的行。 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.
由于任何数据帧中都没有重复的行,因此对于最大数据集中的至少某些行,我应该得到t = 1。 Can someone figure out what I got wrong?
有人可以找出我做错了什么吗?
Rewritten: 改写:
common <- function(a, b, c, d)
{
Name <- a$Name
inB <- Name %in% b$Name
inC <- Name %in% c$Name
inD <- Name %in% d$Name
which(!(inB | inC | inD))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.