[R] as.POSIXct problem?

Frank E Harrell Jr fharrell at virginia.edu
Fri Jan 3 20:52:03 CET 2003

On Fri, 3 Jan 2003 18:44:25 +0000 (GMT)
ripley at stats.ox.ac.uk wrote:

> > I get NA for any day in 1969 or earlier.  Using a time other than midnight did not help.  So it's not a problem with time zone changes on a given day (thanks, Brian and Don for suggesting I look at that).
> Ahah, so Dirk's guess was right for your machine!  That's a new bug in
> some version of glibc, I suppose.  Exactly what OS are you running, and
> version of glibc (if you can tell)?

I'm running RedHat 8.0 with glibc 2.2.93-5

> > Doing as.POSIXlt works fine, but I want POSIXct variables for storage in data frames.
> >
> > I am at a loss on how to proceed but thanks to all for the help.
> Dirk had a Linux machine in (I believe) the same time zone which
> gave the right answer.  So does mine if I set it to EST.
> Try setting tz="GMT" is as.POSIXct if you don't care about times. It looks
> from reading the code that this will work.  If you are compiling from
> source, about line 220 of src/main/datetime.c reads

Setting tz='GMT' as you suggested did indeed work, seemingly back 2000 years, except for a shift of one day due I suppose to time zone differences.

> x <- strptime(c('10/15/1969','12/31/2002'),format='%m/%d/%Y')
> as.POSIXct(x,tz='GMT')
[1] "1969-10-14 20:00:00 EDT" "2002-12-30 19:00:00 EST"

Thanks very much for the workaround Brian.   Oddly enough, 10/15/1203 works without tz='GMT' (but with a day shift) but 10/15/1969 will not (gives NA). 
 - Frank

> #ifdef Win32
>        tm->tm_year >= 70)
> #else
>        tm->tm_year > 02)
> #endif
> and your machine seems to need the Win32 branch.  You might also need it
> in localtime0 a few lines later.
> We will probably need a configure test for this particular type of
> brokenness.
> -- 
> 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

Frank E Harrell Jr              Prof. of Biostatistics & Statistics
Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
U. Virginia School of Medicine  http://hesweb1.med.virginia.edu/biostat

More information about the R-help mailing list