[R] as.POSIXct questions

R. Michael Weylandt michael.weylandt at gmail.com
Thu Jul 19 22:45:10 CEST 2012


Short answer:

as.POSIXct(0, origin = ISOdatetime(1970,1,1,10,0,0, tz = "GMT"))

Long answer -- as.POSIXct goes through a somewhat crazy chain of
method dispatch to work, and only sometimes cares about the tz
argument.

For your case

as.POSIXct(x)  -- calls -->

as.POSIXct.numeric(x) -- calls -->

as.POSIXct(origin) -- calls -->

as.POSIXct.default

which keeps the time zone of the inputted argument. (And that's a
relatively easy one!)

In none of these is the tz used because it already has a tz by way of
origin which gets the default from ISOdatetime unless otherwise
specified.

(I think, but I'm usually wrong about these things)

Best,
Michael

On Thu, Jul 19, 2012 at 3:31 PM, Jack Tanner <ihok at hotmail.com> wrote:
> The following three calls all produce the same result (my machine is in EST):
>
>> as.POSIXct(0, tz="", origin=ISOdatetime(1970,1,1,10,0,0))
> [1] "1970-01-01 10:00:00 EST"
>> as.POSIXct(0, tz="EST", origin=ISOdatetime(1970,1,1,10,0,0))
> [1] "1970-01-01 10:00:00 EST"
>> as.POSIXct(0, tz="GMT", origin=ISOdatetime(1970,1,1,10,0,0))
> [1] "1970-01-01 10:00:00 EST"
>
> EST is -5:00 GMT. Is it a bug that the third call above does not produce
>
> [1] "1970-01-01 5:00:00 EST"
>
> ?
>
> (Under R 2.15.1, Windows 64-bit)
>
> ______________________________________________
> 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.



More information about the R-help mailing list