R - 合并数据,保存失败的输出
R - Merge data, save failed output
我合并了一些数据,效果很好。但我想知道遗漏了哪些数据,即没有 "find" 匹配数据并因此被丢弃的数据。有没有办法做这样的事情:
not_merged<-!merge(df1,df2)
以上代码为伪代码。下面的代码不是。
df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Toaster", 3), rep("Radio", 3)))
df2 = data.frame(CustomerId = c(2, 4, 6), State = c(rep("Alabama", 2), rep("Ohio", 1)))
merged<-merge(df1,df2)
您可以使用 dplyr
包中的 anti_join
:
library(dplyr)
anti_join(df1, df2)
我合并了一些数据,效果很好。但我想知道遗漏了哪些数据,即没有 "find" 匹配数据并因此被丢弃的数据。有没有办法做这样的事情:
not_merged<-!merge(df1,df2)
以上代码为伪代码。下面的代码不是。
df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Toaster", 3), rep("Radio", 3)))
df2 = data.frame(CustomerId = c(2, 4, 6), State = c(rep("Alabama", 2), rep("Ohio", 1)))
merged<-merge(df1,df2)
您可以使用 dplyr
包中的 anti_join
:
library(dplyr)
anti_join(df1, df2)