[R] timestamp shifted by hour(s) while mering zoo objects

CHI-YU kigiokli at gmail.com
Sun Mar 7 21:36:52 CET 2010


Thanks Gabor,

You're right. The problem comes from the environment variable TZ. I just 
tried the Sys.getenv("TZ") and it's nothing there. After I have set the 
environment variable TZ as the same as the data, let's say 
Sys.setenv(TZ="GMT+1"), the problem is gone.

In order to complete the problem I've mentioned, here are the data and 
the code:
data01.txt
% time[GMT+1:00] Temperature[°C]
00:00:00 01.01.2007, 8.0250
01:00:00 01.01.2007, 8.0167
02:00:00 01.01.2007, 10.0917
03:00:00 01.01.2007, 8.6750
04:00:00 01.01.2007, 6.3250

data02.txt
% time[GMT+1:00] Conductance[µS]
00:00:00 01.01.2007, 257.58
01:00:00 01.01.2007, 239.92
02:00:00 01.01.2007, 234.00
03:00:00 01.01.2007, 220.00
04:00:00 01.01.2007, 206.92

data01 <- read.zoo("data01.txt", sep=",", format="%H:%M:%S %d.%m.%Y", 
tz="GMT+1", strip.white=TRUE, skip=1)

data02 <- read.zoo("data02.txt", sep=",", format="%H:%M:%S %d.%m.%Y", 
tz="GMT+1", strip.white=TRUE, skip=1)

merge.zoo(data01, data02)

Besides, thanks for your recommendation, and I'll have a check the R 
News 4/1.

Regards,
Keith

Gabor Grothendieck wrote:
> Without reproducible code (that means we can copy your code from your
> post, paste it into our session and see the same problem that you see)
> there is not much that can be said that addresses your specific
> situation but in terms of general advice:
> 
> - the inappropriate use of time zones is a frequent source of errors
> in R for the unwary and you should read R News 4/1 to find out more
> about this.
> 
> - if after reading that you still want to use POSIXct your best bet is
> to set the time zone of your session to GMT and work entirely in GMT:
> Sys.setenv(TZ = "GMT")
> 
> 
> On Sun, Mar 7, 2010 at 12:20 PM, Keith <kigiokli at gmail.com> wrote:
>> Dear R-users,
>>
>> I have two regular hourly time series data which were recorded in time zone
>> GMT+1, and now I would like to merge them together for further analyses.
>> Here I used zoo and merge.zoo for my purposes and everything worked fine
>> except the timestamp shifted 2 hours after merging which bugs me a little
>> bit. Here is the example:
>>
>> data01
>> 00:00:00 01.01.2007, 8.0250
>> 01:00:00 01.01.2007, 8.0167
>> 02:00:00 01.01.2007, 10.0917
>> 03:00:00 01.01.2007, 8.6750
>> 04:00:00 01.01.2007, 6.3250
>>
>> data02
>> 00:00:00 01.01.2007, 257.58
>> 01:00:00 01.01.2007, 239.92
>> 02:00:00 01.01.2007, 234.00
>> 03:00:00 01.01.2007, 220.00
>> 04:00:00 01.01.2007, 206.92
>>
>> which are both read into zoo object, data01 and data02, separately by
>> setting tz = "GMT+1". However, while merging function is operated, the
>> result is
>>
>> merge.zoo(data01, data02)
>>                     data01 data02
>> 2007-01-01 02:00:00  8.0250 257.58
>> 2007-01-01 03:00:00  8.0167 239.92
>> 2007-01-01 04:00:00 10.0917 234.00
>> 2007-01-01 05:00:00  8.6750 220.00
>> 2007-01-01 06:00:00  6.3250 206.92
>>
>> which is 2 hours shifted comparing to the original data. I am wondering if
>> it's the problem of tz parameter. Hence, I re-read the data by setting tz =
>> "GMT", and the merging result is
>>
>> merge.zoo(data01, data02)
>>                     data01 data02
>> 2007-01-01 01:00:00  8.0250 257.58
>> 2007-01-01 02:00:00  8.0167 239.92
>> 2007-01-01 03:00:00 10.0917 234.00
>> 2007-01-01 04:00:00  8.6750 220.00
>> 2007-01-01 05:00:00  6.3250 206.92
>>
>> which is 1 hour shifted. I only noticed this but don't know why and how to
>> fix it. Does anyone have idea about this issue?
>>
>> Best regards,
>> Keith
>>
>> ______________________________________________
>> 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