[Rd] POSIXct Formating Error (PR#9819)

From: <josh.quigley_at_tibra.com.au>
Date: Tue, 31 Jul 2007 10:09:41 +0200 (CEST)


To Whom It May Concern:  

The following appears to be a bug in the way POSIXct dates are formated.

The example is forced, but occurs naturally when importing Excel type dates

(where fractional part is fraction of a day) and small rounding errors result.  

As shown, looking at the POSIXct class, it looks as if both times are 16:11:03 (truncation)

Looking at as.numeric.POSIXct, it looks as if the times should be 1 second different (rounding)  

Looking at more digits shows the problem, the character format is truncating the fractional part while

the numeric format is rounding it.  

The workaround of rounding the POSIXct is non-trivial, as it is not possible (or at least I can't)

manipulate the POSIXct number directly. Rather, you need to go to POSIXlt, round and then go back.  

> a <- as.POSIXct(c("2007-07-27 16:11:03.000002", "2007-07-27
16:11:03.999995"))

> a
 

[1] "2007-07-27 16:11:03 AUS Eastern Standard Time"

[2] "2007-07-27 16:11:03 AUS Eastern Standard Time"  

> as.numeric(a)
 

[1] 1185516663 1185516664  

> format(as.numeric(a), digits=20)
 

[1] "1185516663.000002" "1185516663.999995"    

Yours truly,  

Josh Quigley.  

Version:

 platform = i386-pc-mingw32

 arch = i386

 os = mingw32

 system = i386, mingw32

 status =

 major = 2

 minor = 5.0

 year = 2007

 month = 04

 day = 23

 svn rev = 41293

 language = R

 version.string = R version 2.5.0 (2007-04-23)  

Windows XP (build 2600) Service Pack 2.0  

Locale:

LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MONETAR Y=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252  

Search Path:

 .GlobalEnv, package:zoo, package:chron, package:RDCOMClient, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads, package:base    

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 31 Jul 2007 - 08:18:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 31 Jul 2007 - 14:37:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.