Exams Knowledge Hub

MCQs for Competitive Exams, School & College Exams

Module: | Base R Data Structures & Subsetting

Q5: Consider the following statements regarding equality testing using all.equal() in R:

1. Unlike the strict == operator, all.equal() evaluates near equality, natively allowing for computational tolerance in floating-point numeric comparisons.
2. If the objects compared using all.equal() are fundamentally different, the function returns a character vector detailing the discrepancies rather than a simple boolean FALSE.
3. Following the R 4.4.0 patch, all.equal(obj, simple, check.class=FALSE) now accurately evaluates to TRUE when simple is a bare atomic vector and obj possesses a simple class.

Which of the above statements is/are correct?
A
Only 1
B
Only 1 and 2
C
Only 2 and 3
D
1, 2, and 3
✅ Correct Answer: D
🎯 Quick Answer:
D. 1, 2, and 3 are all correct statements.
Concept Definition: The all.equal() function is an S3 generic explicitly used to test if two objects are nearly equal, which is essential for mitigating the floating-point arithmetic errors mathematically inherent in modern computing.
Structural Breakdown: It takes target and current parameters.
If they match within a default tolerance level, it returns TRUE.
If they do not, it returns a diagnostic character string explaining the difference.
Historical/Related Context: In earlier R versions, comparing a classed vector with an unclassed bare atomic vector could occasionally yield false negatives even if the check.class=FALSE directive was explicitly set by the user.
Causal Reasoning: A major bug fix logged as PR#18971 was integrated into the R 4.4.0 release on April 24, 2024.
This fix guaranteed that all.equal() honors the check.class=FALSE directive perfectly when comparing simple classed objects directly to bare atomic vectors.