Skip to content

zoo: bug / feature replacing coredata - subsetting by dates

2 messages · Phil Joubert, Gabor Grothendieck

#
Bloomberg free example below:

vdPrices <- zoo(c(0.01,0.01,0.01,0.01,0.01), order.by=seq(chron("31/12/1998", format="d/m/y"), chron("04/01/1999", format="d/m/y"), by="day"))
length(vdPrices)

vdDivs <- zoo(c(100,100), as.chron(c("01/01/1999","01/02/2009")))

coredata(vdPrices[index(vdDivs+vdPrices)]) <- coredata(vdDivs+vdPrices)
length(vdPrices)

Its a little clunky, but thats because I've tried to replicate the returns from the BBG calls as closely as possible.

I also noticed a mistake in the earlier code snippet - the merge() call should not be there.

thanks
Phil
--- On Fri, 4/24/09, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:

            
#
This has nothing to do with zoo but is just how R works.  For
example consider this which does not use zoo at all:

      library(chron)
      p <- 1:5
      p[chron("01/01/09")] <- 100
      length(p)

The length of the result is 14245 because the index is unclassed
giving 14245 so 100 is assigned to the 14245th element of p and
since p only has 5 elements its extended to have 14245 elements.

Normally in zoo (as is the case with ts in the core of R) one uses a
window<- method like this:

     v <- vdDivs + vdPrices
     window(vdPrices, index(v)) <- v
On Fri, Apr 24, 2009 at 10:52 AM, Phil Joubert <philjoubert at yahoo.com> wrote: