Skip to content
Prev 199848 / 398506 Next

Unexpected behaviour for as.date()

G'day Isabella,

On Tue, 10 Nov 2009 18:40:11 -0800
"Isabella Ghement" <isabella at ghement.ca> wrote:

            
As far as I can tell, there is no package called "dates", did you mean
the package "date"?
Are you sure that you are doing what your comments imply?  Try:

R> library(date)
R> as.date("02-MAY-01", order="mdy")
[1] 2May1
R> as.date("02-MAY-2001", order="mdy")
[1] 2May2001
R> as.numeric(as.date("02-MAY-01", order="mdy"))
[1] -21428
R> as.numeric(as.date("02-MAY-2001", order="mdy"))
[1] 15097
My guess it thinks it comes from the year 0.  Not sure why it cannot
handle such dates.  But then, as far as I know, there is actually some
discussion about whether the year 0 exist or whether we went straight
from 1BC to 1AD......
Presumably you will need something like:

R> as.date(sub("-00", "-2000", "02-MAY-00"))
[1] 2May2000

HTH.

Cheers,

	Berwin

========================== Full address ============================
Berwin A Turlach                      Tel.: +61 (8) 6488 3338 (secr)
School of Maths and Stats (M019)            +61 (8) 6488 3383 (self)
The University of Western Australia   FAX : +61 (8) 6488 1028
35 Stirling Highway                   
Crawley WA 6009                e-mail: berwin at maths.uwa.edu.au
Australia                        http://www.maths.uwa.edu.au/~berwin