[英]R match/%in% for data frames
I'm trying to find those rows in a data frame, which appear in another data frame. 我试图在一个数据框中找到那些行,这些行出现在另一个数据框中。
df1 <- data.frame(V1=c(0,1,1,1), V2=c(0,1,0,2))
df2 <- data.frame(V1=c(0,1), V2=c(0,1))
in_df(df1, df2) # should yield c(T, T, F, F)
Is there a function which calculates this? 是否有计算此功能的函数?
Try 尝试
as.character(interaction(df1)) %in% as.character(interaction(df2))
#[1] TRUE TRUE FALSE FALSE
There is a duplicated.data.frame
method that can be combined with rbind
: 有一个
duplicated.data.frame
rbind
方法可以与rbind
结合使用:
in_df <- function(d1,d2) duplicated(rbind(d2,d1))[-(1:nrow(d2)) ]
in_df(df1, df2)
#[1] TRUE TRUE FALSE FALSE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.