[R-SIG-Finance] Timezone magic with zoo, POSIXct and strptime?

Gabor Grothendieck ggrothendieck at gmail.com
Sat Oct 13 13:59:23 CEST 2007


The zoo function and most functions in the zoo package have
no understanding of date time classes and only require that
such classes have ordered elements and support certain methods
as defined in ?zoo so zoo is irrelevant for understanding dates, times
and timezones.

If you use chron you won't have to fight with time zones in the first place.
See R News 4/1.

Also please read the last line of every message to r-help.

On 10/13/07, icosa atropa <icos.atropa at gmail.com> wrote:
> Just when I thought I was getting the hang of timezones...
>
> I'm trying to remove the Daylight Savings timeshift from data that I'm
> turning into zoo objects, using a POSIXct index.  My first try, as
> expected, gives duplicate entries at timezone boundaries:
>
> abq.z.full = zoo(abq[,4], order.by=as.POSIXct(strptime(paste(abq[,1],
> abq[,2]), format='%Y%m%d %H%M%S')))
> Warning message:
> In zoo(abq[, 4], order.by = as.POSIXct(strptime(paste(abq[, 1],  :
>  some methods for âzooâ are not unique
>
> and here are some of the duplicates:
> abq.z.full[duplicated(index(abq.z.full)),]
> 2002-10-27 01:00:00 2002-10-27 01:15:00 2002-10-27 01:30:00 2002-10-27 01:45:00
>                200                 200                 200                 200
> 2003-10-26 01:00:00 2003-10-26 01:15:00 2003-10-26 01:30:00 2003-10-26 01:45:00
>                129                 129                 129                 129
>
> After a lot of experimenting, I find that breaking the data into
> subsets by timezone and then rbinding them works correctly.  Yet I
> never inform strptime or as.POSIXct of the timezone.  Particularly,
> the zoo() call is identical to above, just on different subsets.
>
> > tmp.df= abq[abq[,3]=='MDT',];
> abq.z.mdt = zoo(tmp.df[,4],
> order.by=as.POSIXct(strptime(paste(tmp.df[,1], tmp.df[,2]),
> format='%Y%m%d %H%M%S')))
> > tmp.df= abq[abq[,3]=='MST',];
> abq.z.mst = zoo(tmp.df[,4],
> order.by=as.POSIXct(strptime(paste(tmp.df[,1], tmp.df[,2]),
> format='%Y%m%d %H%M%S')))
> > abq.z = rbind(abq.z.mst, abq.z.mdt)
>
> I'm mystified as to how the 2 separate zoo(order.by=as.POSIXct...)
> operations works but one doesn't, without my ever having to tell
> strptime or as.POSIXct the timezone.  Is there more going on beneath
> the surface that I'm missing?
>
> thanks,
> christian
> --
> Far better an approximate answer to the right question, which is often
> vague, than the exact answer to the wrong question, which can always
> be made precise -- j.w. tukey
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.



More information about the R-SIG-Finance mailing list