How do I check if two objects, e.g. dataframes, are value equal in R?
By value equal, I mean the value of each row of each column of one dataframe is equal to the value of the corresponding row and column in the second dataframe.
How do I check if two objects, e.g. dataframes, are value equal in R?
By value equal, I mean the value of each row of each column of one dataframe is equal to the value of the corresponding row and column in the second dataframe.
It is not clear what it means to test if two data frames are "value equal" but to test if the values are the same, here is an example of two non-identical dataframes with equal values:
To test if all values are equal:
To test if objects are identical (they are not, they have different column names):
In addition, identical is still useful and supports the practical goal:
We can use the R package
compare
to test whether the names of the object and the values are the same, in just one step.In case we only care about equality of the values, we can set
ignoreNames=TRUE
The package has additional interesting functions such as
compareEqual
andcompareIdentical
.