[R] timezone attribute lost during operations

Thomas Mang Thomas.Mang at fiwi.at
Fri Nov 21 13:22:24 CET 2008


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 = 
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 ?


More information about the R-help mailing list