[R] RE: aggregating dates
Gabor Grothendieck
ggrothendieck at myway.com
Tue Feb 1 17:49:20 CET 2005
Gabor Grothendieck <ggrothendieck <at> myway.com> writes:
:
: The issue is just that you need to add POSIXt to the class vector to
: be absolutely correct.
:
: class(x) <- c("POSIXt", "POSIXct")
:
: is the same as
:
: structure(x, class = c("POSIXt", "POSIXct"))
:
: The only reason the table used the latter was to put it in functional
: form rather than lvalue form. The class form that you are using does
: have the advantage of not manipulating the underlying representation
: directly. The way that class(x) <- "POSIXct" might ail would be if there
: were a POSIXt method that should be applied since it would then never
: find it.
Just a follow up.
Here is a simple example of
class(y) <- "POSIXct"
failing while
class(x) <- c("POSIXt", "POSIXct")
works.
In the first example below (x) the class is correct and converting the
POSIXct date to character gives the expected date representation
but in the second example (y) the class is incomplete and converting
it to character gives an unexpected result:
R> x <- structure(0, class = c("POSIXt", "POSIXct"))
R> as.character(x)
[1] "1969-12-31 19:00:00"
R> y <- structure(0, class = "POSIXct")
R> as.character(y)
[1] "0"
More information about the R-help
mailing list