1

Is there a simple way to find which element (row and column) that differ between two data frames in R? I know I can get which rows are different using setdiff() or dplyr::anti_join(). I also know it is possible using other software, but I’d like to know if I can do this inside R (or RStudio).

vrognas
  • 33
  • 6

1 Answers1

1

Have a look at the waldo library.

> library(waldo)
> a = data.frame(x=1:3, y=c("a", "b", "c"))
> b = data.frame(x=1:3, y=c("a", "B", "c"))
> compare(a, b)
old vs new
           y
  old[1, ] a
- old[2, ] b
+ new[2, ] B
  old[3, ] c

`old$y`: "a" "b" "c"
`new$y`: "a" "B" "c"
dalloliogm
  • 8,718
  • 6
  • 45
  • 55
  • 2
    `waldo` is cool but in simple examples like that I prefer the output of `which(a!=b, arr.ind=T)`. – SamR May 09 '22 at 13:46