[R] tzone and DST

Gabor Grothendieck ggrothendieck at gmail.com
Fri Feb 11 01:22:17 CET 2011


On Thu, Feb 10, 2011 at 7:06 PM, Bill Harris
<bill_harris at facilitatedsystems.com> wrote:
> 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?

Use chron.  It does not use time zones so you can't have any of these
problems in the first place.  See the help desk article in R News 4/1
for more discussion.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list