Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between identical(x, y) and isTRUE(all.equal(x, y))?

Is there any difference between testing isTRUE(all.equal(x, y)) and identical(x, y)?

The help page says:

Don't use 'all.equal' directly in 'if' expressions — either use 'isTRUE(all.equal(....))' or 'identical' if appropriate.

but that "if appropriate" leaves me in doubt. How do I decide which of the two is appropriate?

like image 362
mariotomo Avatar asked Aug 03 '10 10:08

mariotomo


People also ask

What is all equal in R?

all. equal(x, y) is a utility to compare R objects x and y testing 'near equality'. If they are different, comparison is still made to some extent, and a report of the differences is returned. Do not use all.

Is equal in R?

setequal() function in R Language is used to check if two objects are equal. This function takes two objects like Vectors, dataframes, etc. as arguments and results in TRUE or FALSE, if the Objects are equal or not.


1 Answers

all.equal tests for near equality, while identical is more exact (e.g. it has no tolerance for differences, and it compares storage type). From ?identical:

The function ‘all.equal’ is also sometimes used to test equality this way, but was intended for something different: it allows for small differences in numeric results.

And one reason you would wrap all.equal in isTRUE is because all.equal will report differences rather than simply return FALSE.

like image 172
Joshua Ulrich Avatar answered Sep 22 '22 14:09

Joshua Ulrich