0

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

viki
  • 1
  • 3

2 Answers2

0

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)
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
0
library(dplyr)

df2 %>% 
  anti_join(df1)

  id name
1  2   bc

DATA:

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)
Lennyy
  • 5,932
  • 2
  • 10
  • 23