[R] ISOdate() and strptime()
RINNER Heinrich
H.RINNER at tirol.gv.at
Fri Nov 14 11:13:26 CET 2003
Dear R-people!
I am using R 1.8.0, under Windows XP.
While using ISOdate() and strptime(), I noticed the following behaviour when
"wrong" arguments (e.g., months>12) are given to these functions:
> ISOdate(year=2003,month=2,day=20) #ok
[1] "2003-02-20 13:00:00 Westeuropäische Normalzeit"
> ISOdate(year=2003,month=2,day=30) #wrong day, but returns a value
[1] "2003-03-02 13:00:00 Westeuropäische Normalzeit"
> ISOdate(year=2003,month=2,day=35) #wrong day, and returns NA
[1] NA
> ISOdate(year=2003,month=2,day=40) #wrong day, but returns a value
[1] "2003-02-04 01:12:00 Westeuropäische Normalzeit"
> ISOdate(year=2003,month=22,day=20) #wrong month, but returns a value
[1] "2003-02-02 21:12:00 Westeuropäische Normalzeit"
And almost the same with strptime():
> strptime("2003-02-20", format="%Y-%m-%d")
[1] "2003-02-20"
> strptime("2003-02-30", format="%Y-%m-%d")
[1] "2003-03-02"
> strptime("2003-02-35", format="%Y-%m-%d")
[1] NA
> strptime("2003-02-40", format="%Y-%m-%d")
[1] "2003-02-04"
> strptime("2003-22-20", format="%Y-%m-%d")
[1] NA
Is this considered to be a user error ("If you put garbage in, expect to get
garbage out"), or would it be safer to generally return Nas, as in
ISOdate(year=2003,month=2,day=35)?
-Heinrich.
More information about the R-help
mailing list