[Rd] POSIXct Formating Error (PR#9819)

josh.quigley at tibra.com.au josh.quigley at tibra.com.au
Tue Jul 31 10:09:41 CEST 2007


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.

 

------------------------------------------------------------------ Example
----------

 

> 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.

 

-- please do not edit the information below
---------------------------------------------

 

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]]



More information about the R-devel mailing list