Hi all, I bumped into this awkward zoo behaviour. I'd be half tempted to call it a bug, what do you think? It's annoying to work around it :( I wonder if this was the behaviour of older zoo versions, I can't remember coming across this sort of thing...> version_ platform i386-pc-solaris2.10 arch i386 os solaris2.10 system i386, solaris2.10 status major 2 minor 10.1 year 2009 month 12 day 14 svn rev 50720 language R version.string R version 2.10.1 (2009-12-14)> packageDescription("zoo")Package: zoo Version: 1.6-2 Date: 2009-11-23>t1 = zoo(-100, as.POSIXct("2009-12-31")+(2:10)*60*60*24) >t2 = zoo(matrix(0), index(t1)[1]-1) >colnames(t1)="test" >colnames(t2) = colnames(t1)> t12010-01-02 2010-01-03 2010-01-04 2010-01-05 2010-01-06 2010-01-07 2010-01-08 -100 -100 -100 -100 -100 -100 -100 2010-01-09 2010-01-10 -100 -100> t22010-01-01 23:59:59 0>rbind(t1,t2)2010-01-01 23:59:59 0 2010-01-02 00:00:00 -100 2010-01-03 00:00:00 0 2010-01-04 00:00:00 -100 2010-01-05 00:00:00 0 2010-01-06 00:00:00 -100 2010-01-07 00:00:00 0 2010-01-08 00:00:00 -100 2010-01-09 00:00:00 0 2010-01-10 00:00:00 -100 Warning message: In rbind(c(-100, -100, -100, -100, -100, -100, -100, -100, -100), : number of columns of result is not a multiple of vector length (arg 1)>rbind(as.xts(t1),as.xts(t2))[,1] 2010-01-01 23:59:59 0 2010-01-02 00:00:00 -100 2010-01-03 00:00:00 -100 2010-01-04 00:00:00 -100 2010-01-05 00:00:00 -100 2010-01-06 00:00:00 -100 2010-01-07 00:00:00 -100 2010-01-08 00:00:00 -100 2010-01-09 00:00:00 -100 2010-01-10 00:00:00 -100 And also:> t1 = zoo(matrix(-100,ncol=1), as.POSIXct("2009-12-31")+(2:10)*60*60*24) > rbind(t1,t2)2010-01-01 23:59:59 0 2010-01-02 00:00:00 -100 2010-01-03 00:00:00 -100 2010-01-04 00:00:00 -100 2010-01-05 00:00:00 -100 2010-01-06 00:00:00 -100 2010-01-07 00:00:00 -100 2010-01-08 00:00:00 -100 2010-01-09 00:00:00 -100 2010-01-10 00:00:00 -100 Cheers, //Giuseppe ---- MAKO ---- This email and any files transmitted with it are confide...{{dropped:14}}
On Wed, 28 Apr 2010, Giuseppe Milicia wrote:> Hi all, > > I bumped into this awkward zoo behaviour. I'd be half tempted to call it > a bug, what do you think?The situation could probably be improved on the zoo side but the source of the problem is clearly user error.> It's annoying to work around it :(You would just have to use it appropriately :-) In addition to that, we can maybe improve warnings/errors.>> t1 = zoo(-100, as.POSIXct("2009-12-31")+(2:10)*60*60*24) >> t2 = zoo(matrix(0), index(t1)[1]-1)Just to be clear: t1 is a vector, t2 is a one-column matrix.>> colnames(t1)="test"This doesn't work and it tells you that it doesn't work. Error in `colnames<-`(`*tmp*`, value = "test") : attempt to set colnames on object with less than two dimensions If you want it to work, then the data in the time series should be a matrix (as you showed at the bottom of your post), e.g.: t1 <- zoo(as.matrix(coredata(t1)), time(t1)) colnames(t1) <- "test" If you do that, everything else will work as expected.>> rbind(t1,t2) > > 2010-01-01 23:59:59 0 > 2010-01-02 00:00:00 -100 > 2010-01-03 00:00:00 0 > 2010-01-04 00:00:00 -100 > 2010-01-05 00:00:00 0 > 2010-01-06 00:00:00 -100 > 2010-01-07 00:00:00 0 > 2010-01-08 00:00:00 -100 > 2010-01-09 00:00:00 0 > 2010-01-10 00:00:00 -100 > Warning message: > In rbind(c(-100, -100, -100, -100, -100, -100, -100, -100, -100), : > number of columns of result is not a multiple of vector length (arg 1)Yes, this is not nice, but it does warn you that something went wrong!>> rbind(as.xts(t1),as.xts(t2))"xts" stores everything internally as a matrix, hence there cannot be a confusion between vectors and matrices. I'll have a look whether we can throw a better warning or maybe handle the border case of rbinding a vector with a one-column matrix. Best, Z
Possibly Parallel Threads
- A zoo question / problem
- How to calculate mean of every nth time series data with zoo or xts ?
- max and min with the indexes in a zoo object (or anything else that could solve the problem)
- as.day() Function (zoo question)
- How to get the date of specific value within a zoo object?