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

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu, 03 Jul 2008 21:10:36 -0400

In the development version of R the output changes to:

> 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-02"
>
> R.version.string

[1] "R version 2.8.0 Under development (unstable) (2008-06-28 r46012)"

On Thu, Jul 3, 2008 at 6:48 PM, Angel Spassov <anspassov_at_googlemail.com> wrote:
> Hi,
>
> 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:
>
> as.Date(as.data.frame(x1)[1,1])
>
> [1] "2008-01-01"
>
> where
>
> as.Date(x1)
>
> [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.
>



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 - 01:14:41 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 - 01:31:32 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