[R] 'as.Date' conversion of classes POSIX*t (problem/feature)?

From: Angel Spassov <anspassov_at_googlemail.com>
Date: Fri, 04 Jul 2008 00:48:12 +0200


I'm working with objects of classes "Date","POSIXlt" and "POSIXct" and still having some Date/Time-related concepts unclear. In the documentation of "as.Date" one can find:

"The 'as.Date' methods accept ... '"POSIXlt"' and '"POSIXct"'. (The last are converted to days by ignoring the time after midnight in the representation of the time in UTC.)"

As far as why "POSIXct" ignores the time after midnight is still open question for me and some basic hints about why this happens would be greatly appreciated? Having mentioned this one can avoid an eventual confusion when interpreting the following:

 x1 = as.POSIXlt("2008-01-02 00:58:00")

x2 = as.POSIXct("2008-01-02 00:58:00")

as.Date(x1); as.Date(x2)

[1] "2008-01-02"

[1] "2008-01-01"

 which happened to me at the beginning. Aside from this, my real problem was with the (very) unexpected behavior of the 'as.data.frame'-function which seems to coerce the class '"POSIXlt"' to class '"POSIXct"' and consequently making my life considerably harder through:


[1] "2008-01-01"



[1] "2008-01-02"

Can anyone offer me a strong evidence that exactly this behaviour of R gives me advantage over the "naturally" expected conversion to "2008-01-02"? Thanks in advance.

        [[alternative HTML version deleted]]

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 04 Jul 2008 - 00:55:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 04 Jul 2008 - 02:31:01 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive