[Rd] [Repost 2/3] Why fix all.equal for POSIXct at 1 msec?

Dirk Eddelbuettel edd at debian.org
Sat Sep 15 20:37:17 CEST 2012


[ Email repost 2 of 3 ]

  From: Dirk Eddelbuettel <edd at debian.org>
  To: R-core <R-core at r-project.org>, Prof Brian D Ripley <ripley at stats.ox.ac.uk>
  Subject: Why fix all.equal for POSIXct at 1 msec? 
  Date: Sat, 28 Jul 2012 10:29:52 -0500
  
  
  In R-devel as of today, the following simple loop
  
  edd at max:~/svn/r-devel$ ~/bin/R-devel.sh
  
  R Under development (unstable) (2012-07-28 r60021) -- "Unsuffered
  Consequenc  es"
  [...]
  
  R> now <- Sys.time();  for (d in seq(-1,-9,by=-1)) { then <- now + 10^d;
  cat  ("10^", d, " identical(): ", identical(now, then), " and all.equal():
  "  , all.equal(now, then), " diff of ", difftime(then, now), "\n", sep="")
  }   
  10^-1 identical(): FALSE and all.equal(): Mean scaled difference: 0.0999999
   diff of 0.0999999
  10^-2 identical(): FALSE and all.equal(): Mean scaled difference:
  0.00999999   diff of 0.00999999
  10^-3 identical(): FALSE and all.equal(): TRUE diff of 0.000999928
  10^-4 identical(): FALSE and all.equal(): TRUE diff of 9.98974e-05
  10^-5 identical(): FALSE and all.equal(): TRUE diff of 1.00136e-05
  10^-6 identical(): FALSE and all.equal(): TRUE diff of 9.53674e-07
  10^-7 identical(): TRUE and all.equal(): TRUE diff of 0
  10^-8 identical(): TRUE and all.equal(): TRUE diff of 0
  10^-9 identical(): TRUE and all.equal(): TRUE diff of 0
  R> 
  
  starts reporting all.equal results up to a millisec when identical()
  clearly  
  shows that a measurable difference is detectable much further.  
  
  Why stop at a msec?  I have using POSIXct to store microsecond data for
  half  
  a decade, and have been very grateful for how well R supports this. I fear
  that having all.equal define such an arbitrary bound will lead people to
  infer that R cannot go further than 10^-2 which is clearly wrong.
  
  For completeness, on r-release I get
  
  
  R> now <- Sys.time();  for (d in seq(-1,-9,by=-1)) { then <- now + 10^d;
  cat  ("10^", d, " identical(): ", identical(now, then), " and all.equal():
  "  , all.equal(now, then), " diff of ", difftime(then, now), "\n", sep="")
  }   
  10^-1 identical(): FALSE and all.equal(): TRUE diff of 0.0999999
  10^-2 identical(): FALSE and all.equal(): TRUE diff of 0.00999999
  10^-3 identical(): FALSE and all.equal(): TRUE diff of 0.000999928
  10^-4 identical(): FALSE and all.equal(): TRUE diff of 9.98974e-05
  10^-5 identical(): FALSE and all.equal(): TRUE diff of 1.00136e-05
  10^-6 identical(): FALSE and all.equal(): TRUE diff of 9.53674e-07
  10^-7 identical(): TRUE and all.equal(): TRUE diff of 0
  10^-8 identical(): TRUE and all.equal(): TRUE diff of 0
  10^-9 identical(): TRUE and all.equal(): TRUE diff of 0
  R> R.Version()["version.string"]
  $version.string
  [1] "R version 2.15.1 (2012-06-22)"
  
  R> 
  
  
  Thanks, Dirk
  
  -- 
  Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  


-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com



More information about the R-devel mailing list