[R] as.POSIXct problem?

Frank E Harrell Jr fharrell at virginia.edu
Fri Jan 3 19:06:02 CET 2003


Thanks very much for all the helpful responses.  In response to Don MacQueen's note,

On Fri, 3 Jan 2003 07:51:42 -0800
Don MacQueen <macq at llnl.gov> wrote:

> 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 unclass(x) has one small difference from yours.  The $isdst element is c(-1,0) instead of c(1,0).

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

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

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.

Frank
-----------------
> 
> 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
> --------------------------------------
> Don MacQueen
> Environmental Protection Department
> Lawrence Livermore National Laboratory
> Livermore, CA, USA
> --------------------------------------


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