Concise way to test if X is within the bounds of Y +/- small tolerance?
Is there a concise way to test whether some number X is within the bounds of anot开发者_JAVA百科her number Y plus or minus some small tolerance?
The all.equal
command allows for a tolerance
parameter so that differences less than the tolerance value are ignored.
Personally, I am rather fond of all.equal
as an alternative to identical
, as it is far more informative. It is applicable to objects that are more general than just a single value (e.g. variable1 and variable2), such as data frames, lists, and more. So, although it will do the trick for your question, it is also more general for when you would like to consider whether two data frames are very nearly the same. This is quite useful when the differences are based on issues in numerical precision very close to the machine tolerance.
精彩评论