[R] Using 'diff' on zoo vs zooreg classes (possible bug?)

Josh Quigley josh.quigley at tibra.com.au
Thu Aug 2 07:45:35 CEST 2007


Hello,


Can anyone explain the following behaviour? To me it seems a bug, but maybe
it is intentional.

It seems that a diff on a zooreg class that is not _strictly_ regular only
considers those entries that are 'deltat' apart.

In the following, diff on the zooreg class only returns values where the
index was one second apart. The example replicates by dev code, but I've
also tested using plain old integer indices, and the behaviour is the same.


Cheers,

Josh.

--- Example ---

input <- "
                   
2007-01-10 11:14:38     27.77     49.50  40.31000  24.07002
2007-01-10 11:14:39     27.77     49.50  40.31000  24.07000
2007-01-10 11:14:40     27.77     49.49  40.31000  24.07000
2007-01-10 11:14:43     27.77     49.49  40.31000  24.07000
2007-01-10 11:14:45     27.77     49.49  40.31000  24.07000
2007-01-10 11:14:46     27.77     49.49  40.31000  24.07000
2007-01-10 11:14:49     27.77     49.49  40.32000  24.07000
2007-01-10 11:14:50     27.77     49.49  40.32782  24.07000
2007-01-10 11:14:51     27.77     49.52  40.32782  24.07000
2007-01-10 11:14:52     27.76     49.53  40.32782  24.07000
2007-01-10 11:15:00     27.76     49.53  40.33000  24.07000
"
dat <- read.table(textConnection(input));

dates <- as.POSIXlt(paste(dat[,1], dat[,2]));
z <- zoo(dat[,3:6], order.by=as.POSIXct(dates));
zr <- zooreg(dat[,3:6], order.by=as.POSIXct(dates));

diff(z)           # Produces correct/expected results
diff(zr)          # Not the result I would expect

--- Output ---

                       V3    V4      V5     V6
2007-01-10 11:14:39  0.00  0.00 0.00000 -2e-05
2007-01-10 11:14:40  0.00 -0.01 0.00000  0e+00    
2007-01-10 11:14:43  0.00  0.00 0.00000  0e+00
2007-01-10 11:14:45  0.00  0.00 0.00000  0e+00
2007-01-10 11:14:46  0.00  0.00 0.00000  0e+00
2007-01-10 11:14:49  0.00  0.00 0.01000  0e+00
2007-01-10 11:14:50  0.00  0.00 0.00782  0e+00
2007-01-10 11:14:51  0.00  0.03 0.00000  0e+00
2007-01-10 11:14:52 -0.01  0.01 0.00000  0e+00
2007-01-10 11:15:00  0.00  0.00 0.00218  0e+00

2007-01-10 11:14:39  0.00  0.00 0.00000 -2e-05
2007-01-10 11:14:40  0.00 -0.01 0.00000  0e+00
2007-01-10 11:14:46  0.00  0.00 0.00000  0e+00
2007-01-10 11:14:50  0.00  0.00 0.00782  0e+00
2007-01-10 11:14:51  0.00  0.03 0.00000  0e+00
2007-01-10 11:14:52 -0.01  0.01 0.00000  0e+00



More information about the R-help mailing list