本帖最后由 ccl 于 2013-11-9 21:07 编辑
sorry,看错了!
identical用于比较精确相等,所以会出现 identical(0.9,1.1-0.2)为FALSE,因为计算机有舍入误差.
all.equal用于比较近似相等,all.equal(0.9,1.1-0.2) 为TRUE。
identical compares the internal representation of the data and returns
TRUE if the objects are strictly identical, and FALSE otherwise. all.equal
compares the "near equality" of two objects, and returns TRUE or display a
summary of the dierences. The latter function takes the approximation of
the computing process into account when comparing numeric values. The
comparison of numeric values on a computer is sometimes surprising!
------《R for Beginners》
Only integers and fractions whose denominator is a power of 2 can be repre-
sented exactly with the floating point representation used for storing numbers
in digital computers (see Section 9.1 for more detail). All other numbers are
subject to rounding error. This necessary limitation has caused many heart-
aches.
------《introduction to scientific programming and simulation using R》
> 1-1/2==1/2
[1] TRUE
> 1-1/3==2/3
[1] FALSE
|