[R] timezone attribute lost during operations

From: Thomas Mang <Thomas.Mang_at_fiwi.at>
Date: Fri, 21 Nov 2008 13:22:24 +0100


Hi,

I was just *highly* surprised to find out that R 2.8.0 (Windows XP) changes the timezone-interpretation during operations on time data, as apparently the timezone attribute is lost and then, for the next interpretation of the timezone, the system settings are used.

Here is sample code (executed under a platform with the system timezone managed by Windows set to "CET", but note that as the input data is GMT I also want all the calculations to occur in GMT):

# input data
Time = as.POSIXct(strptime(c("2007-12-12 14:30:15", "2008-04-14 15:31:34", "2008-04-14 15:31:34"), format = "%Y-%m-%d %H:%M:%S", tz = "GMT"))
Time # OK, time zone is GMT
attr(Time, "tzone") # OK, time zone is GMT

TApply = tapply(1:3, Time, max)
names(TApply) # wrong, names are converted to time zone of system

UTime = unique(Time)
UTime # wrong, again time zone of system is used attr(UTime, "tzone") # == NULL

Now the issue is not that I wouldn't know how to solve the problem (by setting TZ to "GMT" prior to executing the calculations), but I wonder why is R doing this mess at all? Why is it not able to maintain the timezone-information stored in my original vector Time ? Is this behavior supposed to be a feature, or is it a plain bug ?

Thanks,
Thomas



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 21 Nov 2008 - 12:37:02 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 21 Nov 2008 - 13:30:26 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