[R] ISOdate() and strptime()
RINNER Heinrich
H.RINNER at tirol.gv.at
Mon Nov 17 15:45:18 CET 2003
I have followed with interest the discussion on date handling.
I am no expert in these things; all I want to do is convert a character
vector that has been read into R (and which may contain some erroneous
dates) to a "date format", and then do some work with it [e.g., use it in a
plot].
Classes "POSIXlt" and "POSIXct" seem fine to me - for example, they have
very nice and useful "seq" and "plot" methods.
So now I have two more questions:
1. Is it only incomplete or erroneous dates that might be handled
"differently" by ISOdate() or strptime()? Do correct specifications of year,
month and day always give the same results, no matter where or who I am?
2. Can someone point me to a reference that helps me understand why R's (or
the Operating systems?) "best guess at what I intended" turns out to be the
results in the examples I posted in my earlier mail?
Regards,
Heinrich.
> -----Ursprüngliche Nachricht-----
> Von: RINNER Heinrich [mailto:H.RINNER at tirol.gv.at]
> Gesendet: Freitag, 14. November 2003 11:13
> An: 'r-help at stat.math.ethz.ch'
> Betreff: [R] ISOdate() and strptime()
>
>
> 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.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
More information about the R-help
mailing list