How to check if two data frames are equal [duplicate] How to check if two data frames are equal [duplicate] r r

How to check if two data frames are equal [duplicate]


Look up all.equal. It has some riders but it might work for you.

all.equal(df3,df4)# [1] TRUEall.equal(df2,df1)# [1] TRUE


As Metrics pointed out, one could also use identical() to compare the datasets. The difference between this approach and that of Codoremifa is that identical() will just yield TRUE of FALSE, depending whether the objects being compared are identical or not, whereas all.equal() will either return TRUE or hints about the differences between the objects. For instance, consider the following:

> identical(df1, df3)[1] FALSE> all.equal(df1, df3)[1] "Attributes: < Component 2: Numeric: lengths (5, 6) differ >"                                [2] "Component 1: Numeric: lengths (5, 6) differ"                                                [3] "Component 2: Lengths: 5, 6"                                                                 [4] "Component 2: Attributes: < Component 2: Lengths (5, 6) differ (string compare on first 5) >"[5] "Component 2: Lengths (5, 6) differ (string compare on first 5)"   

Moreover, from what I've tested identical() seems to run much faster than all.equal().