[R] tzone and DST

Bill Harris bill_harris at facilitatedsystems.com
Fri Feb 11 01:06:20 CET 2011


I'm reading in ~3 years worth of data that includes hourly timestamps. 
Presumably to avoid DST confusion, all the data is in PST time zone -- no
discontinuities in the spring or fall.

The data comes in a csv file, which I'm reading with

myvariable <- read.csv("my_data_file.csv",header=FALSE,
col.names=c("timedate","values"),colClasses=c("POSIXct","numeric"))

The time zone comes in as PST or PDT, as appropriate.  That leads to
problems in the spring:

> temps$timedate[2185:2190]
[1] "2006-04-02 00:00:00 PST" "2006-04-02 01:00:00 PST"
[3] NA                        "2006-04-02 03:00:00 PDT"
[5] "2006-04-02 04:00:00 PDT" "2006-04-02 05:00:00 PDT"

I presume it gets PST/PDT from my (Windows) system; I can't set it with >
force_tz(ymd_hms("2007-03-11 01:00:00"),tzone="PST") (from the lubridate
package), but see

> force_tz(ymd_hms("2006-04-02 01:00:00"),tzone="America/Los_Angeles")
[1] "2006-04-02 01:00:00 PST"

What I'd like to do is keep all the time in standard time so I don't lose
the 2 a.m. data.  Presumably the damage is done by the time it's read in. 
For example,

> force_tz(temps$timedate[2185:2190], tzone="UTC")
[1] "2006-04-02 00:00:00 UTC" "2006-04-02 01:00:00 UTC"
[3] NA                        "2006-04-02 03:00:00 UTC"
[5] "2006-04-02 04:00:00 UTC" "2006-04-02 05:00:00 UTC"

Any advice?

Thanks,

Bill



More information about the R-help mailing list