[R] Basic question on function "identical"
    Martin Maechler 
    maechler at stat.math.ethz.ch
       
    Sat Dec 13 13:01:19 CET 2003
    
    
  
>>>>> "TL" == Thomas Lumley <tlumley at u.washington.edu>
>>>>>     on Fri, 12 Dec 2003 14:54:51 -0800 (PST) writes:
    TL> On Fri, 12 Dec 2003, John Welsh wrote:
    >> 
    >> 
    >> > for(i in c(1:5)) + { + print(identical(i,1)) + }
    >> 
    >> [1] FALSE [1] FALSE [1] FALSE [1] FALSE [1] FALSE
    >> 
    >> Why don't I get:
    >> 
    >> [1] TRUE [1] FALSE [1] FALSE [1] FALSE [1] FALSE
    >> 
    TL> Because the first element of 1:5 is an integer and 1 is
    TL> a real number.  all.equal() will be TRUE, and == will
    TL> probably be TRUE
definitely will (integers do have exact floating point representations)
In general, use
  ==	     for testing equality of integer numbers (of type "integer" or not)
  all.equal  for testing (near)equality non-integer numbers, and
	     many other more structured objects.
  identical  only if you understand more about the S language ;-)
Martin Maechler
    
    
More information about the R-help
mailing list