[R] c() and dates
Therneau, Terry M., Ph.D.
therneau at mayo.edu
Fri Oct 3 18:18:18 CEST 2014
Well duh -- type "c.Date" at the command prompt to see what is going on. I suspected I
was being dense.
Now that the behaior is clear can I follow up on David W's comment that redfining the
c.Date function as
structure(c(unlist(lapply(list(...), as.Date))), class = "Date")
allows for a more intellegent response, since it allows all of the as.Date machinery to be
brought into play.
It seems like a good idea in general. Would it be a good exchange between the current
"nonsense result, no warning" and the new error messages that would arise, e.g., from
c(as.Date("2000/10/1"), factor('b')).
Terry T.
On 10/03/2014 09:52 AM, peter dalgaard wrote:
> S3 only has single dispatch, so in one case it dispatches to c.Date and in the other to c.POSIXct, both of those return an object of the corresponding class. In both cases, the arguments pass through
>
> c(unlist(lapply(list(...), unclass)))
>
> which doesn't look at the class at all. Since Date objects unclass to days and POSIXct to seconds, something is bound to go wrong.
More information about the R-help
mailing list