[R] Difference between two datetimes

Daniel Nordlund djnordlund at frontier.com
Wed Jan 29 07:40:06 CET 2014


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of David Fox
> Sent: Tuesday, January 28, 2014 5:15 PM
> To: r-help at r-project.org
> Subject: [R] Difference between two datetimes
> 
> I have a data frame with variable "datetime" which is of class POSIXct.
> Consecutive observations are separated by 30 minutes.
> However, some of the differences reported by R give unexpected results.
> For example consider the following two consecutive entries:
> 
> > par.dat$datetime[5944]
> [1] "2010-04-04 02:30:00 EST"
> 
> > par.dat$datetime[5945]
> [1] "2010-04-04 03:00:00 EST"
> 
> When I examine the difference, R reports 1.5 hours instead of 30 minutes:
> 
> > par.dat$datetime[5945]-par.dat$datetime[5944]
> Time difference of 1.5 hours
> 
> On further investigation it appears there's something peculiar to this
> particular date. Other years work fine, eg:
> > as.POSIXct("2011-04-04 03:00:00")- as.POSIXct("2011-04-04 02:30:00")
> Time difference of 30 mins
> 
> > as.POSIXct("2012-04-04 03:00:00")- as.POSIXct("2012-04-04 02:30:00")
> Time difference of 30 mins
> 
> > as.POSIXct("2009-04-04 03:00:00")- as.POSIXct("2009-04-04 02:30:00")
> Time difference of 30 mins
> 
> But when I use 2010 I get a difference of 1.5 hours:
> 
> > as.POSIXct("2010-04-04 03:00:00")- as.POSIXct("2010-04-04 02:30:00")
> Time difference of 1.5 hours
> 
> 
> 
> 
> 
> 
> Any suggestions?
> Thanks,
> David Fox.
> 

Daylight savings time change in Australia?

Dan

Daniel Nordlund
Bothell, WA USA




More information about the R-help mailing list