same(x,y)和isTRUE(all.equal(x,y))有什么区别? [英] What's the difference between identical(x, y) and isTRUE(all.equal(x, y))?
问题描述
测试 isTRUE(all.equal(x,y))
和 identical(x,y)$ c有什么区别吗$ c>?
帮助页面上说:
不要使用'all.equal'直接在'if'
表达式中—可以使用'isTRUE(all.equal(....))'或
'identical'(如果适用)。
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?
推荐答案
all.equal
测试接近相等,而相同
更精确(例如,它对差异没有容忍度,并且比较存储类型)。来自?identical:
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:
函数 all.equal也有时是
,用来测试
的相等性,但其目的是为了与
不同:它允许数值结果中的
小差异。
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.
之所以将 all.equal
包裹在 isTRUE
中是因为 all.equal
将报告差异,而不是简单地返回 FALSE
。
And one reason you would wrap all.equal
in isTRUE
is because all.equal
will report differences rather than simply return FALSE
.
这篇关于same(x,y)和isTRUE(all.equal(x,y))有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!