[R] datetime data and plotting

Gabor Grothendieck ggrothendieck at myway.com
Fri Oct 17 20:20:50 CEST 2003


> From: Dirk Eddelbuettel <edd at debian.org>
>  
> On Fri, Oct 17, 2003 at 01:16:00PM -0400, Gabor Grothendieck wrote:
> > 
> > 
> > The problem is related to time zones. The easiest way to
> > handle this is to avoid using POSIXt and use chron instead
> > so you don't have to worry about them.
> > 
> > require(chron)
> > day <- 6:16
> > dts <- dates(paste("10", day, "03", sep="/"))
> > plot(dts,day)
> > abline(v=dts)
> 
> I don't think I'd call that easiest. Jacob simply did not specify hour,
> minute and second for a display where it mattered (mostly because he only
> plotted 3 points, with 300 it would have close to impossible to discern). 
> 
> One way to address this would be to give a hour and minute as in 
> 
> dates <- strptime(paste(DAY,MONTH,YEAR,"23:59"),"%d %m %Y %H:%M")
> 
> (where I also adjust the format string for the space paste() adds).
> The three plot commands can also be combined into
> 
> plot(dates,WEIGHT.KG,
> ylim=c(0,max(WEIGHT.KG)),
> xlab="Date",ylab="Weight (kg)",type="o")

Unfortunately, that solution will not work in all time zones.  
For example, to get dates to line up in my time zone 
(Eastern Daylight Time) I would have to do this:

  day <- 6:16
  dts <- strptime(paste(day,10,2003,"20:00"),"%d %m %Y %H:%M") 
  plot(dts,day)
  abline(v=as.POSIXct(dts))

Its currently daylight savings time where I am but we are soon 
going to change to standard time for the winter which will force 
this to change shortly so even the above is not sufficient.

Time zones are not part of the problem yet POSIXt forces this 
extraneous complication on you.  chron has no time zones in the 
first place and therefore allows you to work in the natural frame 
of the problem, avoiding subtle problems like this.

This sort of thing has been discussed a number of times and I
had previously suggested that chron be moved to the base or else that
a timezone-less version of POSIXt be added to the base.  See:
https://stat.ethz.ch/pipermail/r-devel/2003-August/027269.html

(I am using R 1.7.1 on Windows 2000.)



_______________________________________________
No banners. No pop-ups. No kidding.
Introducing My Way - http://www.myway.com




More information about the R-help mailing list