[R] How to locate the difference from two data frames

Erik Iverson eriki at ccbr.umn.edu
Thu Apr 8 03:55:40 CEST 2010


Jun Shen wrote:
> Hi, David,
> 
> Thanks for the reply. However str() doesn't tell me exactly which element is
> different. I expect to see a is identical to b. But if there is some minor
> difference (usually by human mistake), I want to know which element
> (numerical or character) is different.
> 

So you're saying you have two data.frames with the same dimensions and want to 
know which elements are different?  What about different attributes such as 
names, labels, etc?

A very naive first attempt might be something like:

df1 <- data.frame(a = 1:10, b = 2:11)
df2 <- data.frame(a = 1:10, b = c(2:10, 12))

mapply("==", df1, df2)



More information about the R-help mailing list