Under platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 1 minor 6.1 year 2002 month 11 day 01 language R> x <- strptime(c('10/10/1969','12/31/2002'),format='%m/%d/%Y') > x[1] "1969-10-10" "2002-12-31"> as.POSIXct(x)[1] NA "2002-12-31 EST" Why the NA? If this is not the preferred way to convert a character string to POSIXct what is? On a more minor note why the EST if no time is printed? Thanks, Frank -- 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
On Thu, Jan 02, 2003 at 08:56:28PM -0500, Frank E Harrell Jr wrote:> Under > > platform i686-pc-linux-gnu > arch i686 > os linux-gnu > system i686, linux-gnu > status > major 1 > minor 6.1 > year 2002 > month 11 > day 01 > language R > > > x <- strptime(c('10/10/1969','12/31/2002'),format='%m/%d/%Y') > > x > [1] "1969-10-10" "2002-12-31" > > as.POSIXct(x) > [1] NA "2002-12-31 EST" > > Why the NA? If this is not the preferred way to convert a character string to POSIXct what is? On a more minor note why the EST if no time is printed?Quick guess: Unix time does start by convention on 1/1/1970 at GMT. Going before it is not within the specs, or safe. Dirk -- Prediction is very difficult, especially about the future. -- Niels Bohr
On Thu, 2 Jan 2003, Frank E Harrell Jr wrote:> Under > > platform i686-pc-linux-gnu > arch i686 > os linux-gnu > system i686, linux-gnu > status > major 1 > minor 6.1 > year 2002 > month 11 > day 01 > language R > > > x <- strptime(c('10/10/1969','12/31/2002'),format='%m/%d/%Y') > > x > [1] "1969-10-10" "2002-12-31" > > as.POSIXct(x) > [1] NA "2002-12-31 EST" > > Why the NA? If this is not the preferred way to convert a characterstring to POSIXct what is? It's a function of your system, which is telling you that is an invalid *time* (it is midnight, BTW). I get> as.POSIXct(x)[1] "1969-10-10 GMT" "2002-12-31 GMT" Did by any chance your locale change time zones that day? Trying giving a valid time as well.> On a more minor note why the EST if no time is printed?Because it has to be in some time zone, and it uses the current one if you did not specify it (there is a tz argument, and it is described on the help page!). As far as I can see from your email headers you are in EST. -- 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
No problem on a couple of systems here, one Solaris and one Mac OS X. See below. The conversion of a character string to a POSIXct is taking place in two steps--character string to POSIXlt, then POSIXlt to POSIXct. Which step has the problem? Compare your unclass(x) with my unclass(x). If it's different, the problem would appear to be in converting text to POSIXlt. My guess would be a bug in the underlying Linux code, since, as Dr. Ripley said, your system thinks it's an invalid time--yet the time is not invalid. Does it fail only on that particular day? If there was a EDT to EST change that day, does it fail on other EDT to EST change days? If there was an EDT to EST change that day, did it occur at the usual 2:00 AM? What about EST to EDT changes? If your character strings were in the ISO standard format, it would be simpler to use as.POSIXct() directly, as in> as.POSIXct(c('1969-10-10','2002-12-31'))[1] "1969-10-10 PDT" "2002-12-31 PST"> class(as.POSIXct(c('1969-10-10','2002-12-31')))[1] "POSIXt" "POSIXct" But you probably don't have that luxury. Even so, it would be interesting to find out if it succeeds on your system. -Don> version_ platform sparc-sun-solaris2.7 arch sparc os solaris2.7 system sparc, solaris2.7 status major 1 minor 6.1 year 2002 month 11 day 01 language R> x <- strptime(c('10/10/1969','12/31/2002'),format='%m/%d/%Y') > x[1] "1969-10-10" "2002-12-31"> as.POSIXct(x)[1] "1969-10-10 PDT" "2002-12-31 PST"> class(x)[1] "POSIXt" "POSIXlt"> unclass(x)$sec [1] 0 0 $min [1] 0 0 $hour [1] 0 0 $mday [1] 10 31 $mon [1] 9 11 $year [1] 69 102 $wday [1] 5 2 $yday [1] 282 364 $isdst [1] 1 0>-------- OS X ----------> version_ platform powerpc-apple-darwin6.2 arch powerpc os darwin6.2 system powerpc, darwin6.2 status major 1 minor 6.1 year 2002 month 11 day 01 language R> x <- strptime(c('10/10/1969','12/31/2002'),format='%m/%d/%Y') > x[1] "1969-10-10" "2002-12-31"> as.POSIXct(x)[1] "1969-10-10 PDT" "2002-12-31 PST"> unclass(x)$sec [1] 0 0 $min [1] 0 0 $hour [1] 0 0 $mday [1] 10 31 $mon [1] 9 11 $year [1] 69 102 $wday [1] 5 2 $yday [1] 282 364 $isdst [1] 1 0 At 8:56 PM -0500 1/2/03, Frank E Harrell Jr wrote:>Under > >platform i686-pc-linux-gnu >arch i686 >os linux-gnu >system i686, linux-gnu >status >major 1 >minor 6.1 >year 2002 >month 11 >day 01 >language R > >> x <- strptime(c('10/10/1969','12/31/2002'),format='%m/%d/%Y') >> x >[1] "1969-10-10" "2002-12-31" >> as.POSIXct(x) >[1] NA "2002-12-31 EST" > >Why the NA? If this is not the preferred way to convert a character >string to POSIXct what is? On a more minor note why the EST if no >time is printed? > >Thanks, > >Frank >-- >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 > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >http://www.stat.math.ethz.ch/mailman/listinfo/r-help-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA --------------------------------------
A summary on this: 1) RedHat 8.0 contains an unreleased version of glibc between the released versions 2.2.5 and 2.3. That version (and >=2.3) have been modified to make dates prior to 1970-01-01 invalid in some cases but not others. We've put a workaround for this in R 1.6.2 (due on Friday), and that checks at run-time for the broken version of glibc. Because of the internal inconsistencies in glibc, you will see inconsistencies in the reporting of DST prior to 1970 (but as POSIXct times they are always valid). This makes it important for users of RH8.0 and other recent Linux distros to update to 1.6.2 when released (or even R-patched now). We used a run-time test to allow for installations which are updated to a `better' glibc. 2) The immediate workaround is as.POSIXct(x, tz="GMT") which avoids the OS's routines altogether. On Thu, 2 Jan 2003, Frank E Harrell Jr wrote:> > x <- strptime(c('10/10/1969','12/31/2002'),format='%m/%d/%Y') > > x > [1] "1969-10-10" "2002-12-31" > > as.POSIXct(x) > [1] NA "2002-12-31 EST" > > Why the NA? If this is not the preferred way to convert a character string to POSIXct what is? On a more minor note why the EST if no time is printed?-- 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