开发者

Concise way to test if X is within the bounds of Y +/- small tolerance?

开发者 https://www.devze.com 2023-04-07 12:01 出处:网络
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 s

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号