[R] as.POSIXct problem?

Don MacQueen macq at llnl.gov
Fri Jan 3 16:53:03 CET 2003


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




More information about the R-help mailing list