How to match two dataframe with unique id to obtain the unmatched data in dataset
df1 id name 1 aa 2 bb 3 cc df2 id name 1 aa 2 bb 2 bc 3 cc
required output: id name 2 bc
It's a simple matter if subsetting with a logical index.
inx <- !df2$name %in% df1$name
df2[inx, ]
# id name
#3 2 bc
Data.
df1 <- read.table(text = "
id name
1 aa
2 bb
3 cc
", header = TRUE)
df2 <- read.table(text = "
id name
1 aa
2 bb
2 bc
3 cc
", header = TRUE)
library(dplyr)
df2 %>%
anti_join(df1)
id name
1 2 bc
df1 <- read.table(text = "
id name
1 aa
2 bb
3 cc", header = T, stringsAsFactors = F)
df2 <- read.table(text = "
id name
1 aa
2 bb
2 bc
3 cc", header = T, stringsAsFactors = F)