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

icosa atropa icos.atropa at gmail.com
Sat Oct 13 13:23:13 CEST 2007


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


More information about the R-SIG-Finance mailing list