[R] converting data to date format

BXC (Bendix Carstensen) bxc at steno.dk
Sat Feb 14 12:36:00 CET 2004


> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Mike Hollegger
> Sent: Saturday, February 14, 2004 12:03 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] converting data to date format
> 
> 
> Dear all,
> 

...snip

> I've tried to bring it in character-format (as.charachter()) 
> followed by
> as.POSIXlt() but I get an error message, that the character 
> string is not in
> a standard unambiguous format, although the date is of format 
> yyyy-mm-dd
> (what is standard format according to R reference manual).

...snip

> Thank you very much for any usefull hint!

There seems to be someting fishy about 1 january 1970, I think it
is a bug in Windows:

> as.POSIXlt("1970-01-01")
Error in fromchar(x) : character string is not in a standard unambiguous
format
> as.POSIXlt("1970-01-02")
[1] "1970-01-02"
> as.POSIXlt("1970-02-01")
[1] "1970-02-01"
> as.POSIXlt("1970-12-31")
[1] "1970-12-31"

A workaround is:

> as.POSIXlt( strptime("1970-01-01",format="%Y-%m-%d") )
[1] "1970-01-01"

A peep at fromchar which is defined inside as.POSIXlt lead one to
try the following:

> is.na( strptime("1970-01-01", f <- "%Y-%m-%d") )
[1] TRUE
> strptime("1970-01-01", f <- "%Y-%m-%d")
[1] "1970-01-01"
> is.na( strptime("1970-01-02", f <- "%Y-%m-%d") )
[1] FALSE
> strptime("1970-01-02", f <- "%Y-%m-%d")
[1] "1970-01-02"

I would like to why this is so. And whether thereason for this
it is beyond R.

Btw, I use:
> version
         _              
platform i386-pc-mingw32
arch     i386           
os       mingw32        
system   i386, mingw32  
status                  
major    1              
minor    8.1            
year     2003           
month    11             
day      21             
language R   

Bendix Carstensen
----------------------
Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 30 75 87 38
fax: +45 44 43 07 06
bxc at steno.dk
www.biostat.ku.dk/~bxc




More information about the R-help mailing list