0

I have two datasets with few identical columns (block, number). One dataset has more number of rows that the other. I want to identify only those rows that differ between the two sets.

block <- c(1:10)
number <- c(1:10)
tray <- c(1:10)

df1 <- data.frame(block, number, tray)

block <- c(1:12)
number <- c(1:12)
key <- c(1:12)

df2 <- data.frame(block, number, key)

If I use library(compare) compare(df1, df2) It generates all FALSE..probably because they differ in one of the three columns. I only want it to compare via block and numebr to get that it differs in block 11, 12 number 11, 12

Rspacer
  • 2,369
  • 1
  • 14
  • 40

1 Answers1

1

You can do it using anti_join from dplyr:

dplyr::anti_join(df2, df1, by = c("block", "number"))

#   block number key
#1    11     11  11
#2    12     12  12
sm925
  • 2,648
  • 1
  • 16
  • 28