Re: [R] how to retain time zone when doing c(POSIXct)

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 28 Sep 2006 - 10:23:19 GMT

Here is one way that does not require explicit assignment of tzone:

rbind(data.frame(x=xx), data.frame(x=xx[1] - 60), data.frame(x=xx[2] + 60))[[1]]

With xx from the post we get:

> rbind(data.frame(x=xx), data.frame(x=xx[1] - 60), data.frame(x=xx[2] + 60))[[1]]
[1] "2006-09-26 12:00:00 GMT" "2006-09-26 13:00:00 GMT" [3] "2006-09-26 11:59:00 GMT" "2006-09-26 13:01:00 GMT" On 9/27/06, Sebastian P. Luque <spluque@gmail.com> wrote:
> Hello,
>
> What is the best way to concatenate POSIXct objects keeping the time zone
> attribute in a program? For example:
>
>
> R> xx <- as.POSIXct(strptime(c("2006-09-26 12:00:00", "2006-09-26 13:00:00"),
> + format="%Y-%m-%d %H:%M:%S"), tz="GMT")
> R> xx
> [1] "2006-09-26 12:00:00 GMT" "2006-09-26 13:00:00 GMT"
>
>
> but, as ?c.POSIXct explains:
>
>
> R> c(xx, xx[1] - 60, xx[2] + 60)
> [1] "2006-09-26 07:00:00 CDT" "2006-09-26 08:00:00 CDT"
> [3] "2006-09-26 06:59:00 CDT" "2006-09-26 08:01:00 CDT"
>
>
> Is there something better/safer than simply setting the "tzone" attribute
> of the new object?
>
>
> Cheers,
>
> --
> Seb
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 Thu Sep 28 20:27:02 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 28 Sep 2006 - 11:30:06 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.