Angel Spassov
2008-Jul-03 22:48 UTC
[R] 'as.Date' conversion of classes POSIX*t (problem/feature)?
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]]
Gabor Grothendieck
2008-Jul-04 01:10 UTC
[R] 'as.Date' conversion of classes POSIX*t (problem/feature)?
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. >