[R] Comparing times in two time zones

James Rome jamesrome at gmail.com
Wed Mar 31 19:57:03 CEST 2010


I have data that is collected in two different time zones
z$OnDateTime <- as.POSIXct(runway$OnDateTime, tz = "EST5EDT",
format="%m/%d/%Y %H:%M")
is in Eastern time, and
zi$ActualOnLocal <- as.POSIXct(oooi$ActualOnLocal, tz="MST7MDT",
format="%m/%d/%Y %H:%M")
is in Mountain".
I converted the runway time to Mountain (I think)
z$OnDateTime = format(runway$OnDateTime, tz="MST7MDT")   

The corresponding times in the two data sets seem identical (within a
few minutes) when printed out:
]> z$ActualOnLocal[1:5]
[1] "2008-11-01 07:49:00 MDT" "2008-11-03 07:58:00 MST"
[3] "2008-11-04 08:04:00 MST" "2008-11-05 07:44:00 MST"
[5] "2008-11-06 07:32:00 MST"
> z$OnDateTime[1:5]
[1] "2008-11-01 07:49:00" "2008-11-03 07:57:00" "2008-11-04 08:04:00"
[4] "2008-11-05 07:43:00" "2008-11-06 07:32:00"

 But when I do
z$dt= as.numeric(difftime(z$ActualOnLocal, z$OnDateTime, units="mins"))
the difference is 120 minutes.

How do I get my date times so that difftime works properly?

Thanks,
Jim Rome



More information about the R-help mailing list