[R] time zones, daylight saving etc.
Carla Meurk
ksm32 at student.canterbury.ac.nz
Wed May 11 05:28:57 CEST 2005
Hi, I have a whole bunch of data, which looks like:
15/03/2003 10:20 1
15/03/2003 10:21 0
15/03/2003 12:02 0
16/03/2003 06:10 0
16/03/2003 06:20 0.5
16/03/2003 06:30 0
16/03/2003 06:40 0
16/03/2003 06:50 0
18/03/2003 20:10 0.5
etc. (times given on a 24 hour clock)
and goes on for years. I have some code:
data<-read.table("H:/rainfall_data.txt",h=T)
library(survival)
datetime <- as.POSIXct(strptime(paste(data$V1, data$V2), "%d/%m/%Y
%H:%M"), tz="NZST")
which produces:
[10] "2003-03-13 21:13:00 New Zealand Daylight Time"
[11] "2003-03-15 13:20:00 New Zealand Daylight Time"
[12] "2003-03-15 22:20:00 New Zealand Daylight Time"
[13] "2003-03-15 22:21:00 New Zealand Daylight Time"
[14] "2003-03-16 00:02:00 New Zealand Daylight Time"
[15] "2003-03-16 18:10:00 New Zealand Standard Time"
[16] "2003-03-16 18:20:00 New Zealand Standard Time"
[17] "2003-03-16 18:30:00 New Zealand Standard Time"
My problem is that "15/03/2003 12:02" has become "16/03/2003 00:02"
i.e. it is 12 hours behind (as is everything else), but also, I do not
want to change time zones.
The 12 hour delay is not really a problem just an annoyance, but the
time zone change is a problem because later on I need to match up data
by time using
mindata<-seq(from=min(datetime),to=max(datetime),by="mins")
newdata<-matrix(0,length(mindata),1)
newdata[match(format.POSIXct(datetime,"%Y %m %d %H
%M"),format.POSIXct(mindata,"%Y %m %d %H %M"))]<-data$V3
and things go wrong here with matching repeating times/missing times
around the timezone changes and, my resulting vector is 1 hour shorter
than my other series. From the R help I see that my OS may be to blame
but, even if I specify tz="GMT" I still get NZST and NZDT. Can someone
help?
I hope this all makes sense
Carla
More information about the R-help
mailing list