[R] Chron, as.POSIXct problem

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Nov 12 16:49:54 CET 2003


Does not happen on Solaris or Linux, so looks like a MacOS X problem.

Here is some crosschecks:

> unclass(datesTest)
[1] -6301 -6300 -6299
attr(,"format")
[1] "m/d/y"
attr(,"origin")
month   day  year
    1     1  1970
> unclass(as.POSIXct(datesTest))
[1] -544406400 -544320000 -544233600


On Wed, 12 Nov 2003, Brian Beckage wrote:

> Dear R list,
> 
> I noticed the following 'problem' when changing the format of dates 
> created with seq.dates() (from the Chron library) using as.POSIXct() 
> (R 1.8.0 on OSX 10.2.8):
> 
> >  datesTest<-seq.dates(from="10/01/1952", length=3, by="days");
> >  datesTest
> [1] 10/01/52 10/02/52 10/03/52
> 
> # Now changing the format to show year as 1952.
> 
> >  datesTest<-format(as.POSIXct(datesTest), "%m/%d/%Y")
> >  datesTest
> [1] "09/30/1952" "10/01/1952" "10/02/1952"
> >
> 
> The dates were shifted by one day.  The work around is simple enough, e.g.,
> 
> >  datesTest<-format(as.POSIXct(datesTest+1), "%m/%d/%Y")
> [1] "10/01/1952" "10/02/1952" "10/03/1952"
> 
> but I wonder if this is the intended behavior?
> 
> Brian
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list