Skip to content

Problem with merging two zoo objects

5 messages · Achim Zeileis, Dieter Menne, Gabor Grothendieck +1 more

#
Dear all, I have following 2 zoo objects. However when I try to merge those 2 objects into one, nothing is coming as intended. Please see below the objects as well as the merged object:
V2   V3   V4   V5
2010-10-15 13:43:54 73.8 73.8 73.8 73.8
2010-10-15 13:44:15 73.8 73.8 73.8 73.8
2010-10-15 13:45:51 73.8 73.8 73.8 73.8
2010-10-15 13:46:21 73.8 73.8 73.8 73.8
2010-10-15 13:47:27 73.8 73.8 73.8 73.8
2010-10-15 13:47:54 73.8 73.8 73.8 73.8
2010-10-15 13:49:51 73.7 73.7 73.7 73.7
V2   V3   V4   V5
2010-10-15 12:09:12 74.0 74.0 74.0 74.0
2010-10-15 12:09:33 73.9 73.9 73.9 73.9
2010-10-15 12:20:36 74.0 74.0 74.0 74.0
2010-10-15 12:30:36 74.0 74.0 74.0 74.0
2010-10-15 12:41:03 73.7 73.7 73.7 73.7
V2.dat11 V3.dat11 V4.dat11 V5.dat11 V2.dat22 V3.dat22 V4.dat22 V5.dat22
2010-10-15 12:09:12       NA       NA       NA       NA       NA       NA       NA       NA
2010-10-15 12:09:33       NA       NA       NA       NA       NA       NA       NA       NA
2010-10-15 13:43:54       NA       NA       NA       NA       NA       NA       NA       NA
2010-10-15 13:44:15       NA       NA       NA       NA       NA       NA       NA       NA
2010-10-15 13:45:51       NA       NA       NA       NA       NA       NA       NA       NA
2010-10-15 13:46:21       NA       NA       NA       NA       NA       NA       NA       NA
2010-10-15 13:47:27       NA       NA       NA       NA       NA       NA       NA       NA
2010-10-15 13:47:54       NA       NA       NA       NA       NA       NA       NA       NA
2010-10-15 13:49:51       NA       NA       NA       NA       NA       NA       NA       NA
Warning messages:
1: In MATCH(x, x) == seq_len(length(x)) :
  longer object length is not a multiple of shorter object length
2: In MATCH(x, x) == seq_len(length(x)) :
  longer object length is not a multiple of shorter object length

If somebody points me whether I went wrong, it would be really great.

Thanks
#
On Fri, 15 Oct 2010, Megh Dal wrote:

            
merge() does cbind() (among some more general computations), I guess you 
want rbind().

Try rbind(dat11, dat22).

hth,
Z
#
Megh wrote:
Since the simulated example works, it must have to do with your data. Try
str(dat11), str(dat12), maybe something strange has crept in.

Dieter


library(zoo)
x.date <- as.Date(paste(2003, 02, c(1, 3, 7, 9, 14), sep = "-"))
x <- zoo(matrix(1:10, ncol = 2), x.date)
x
str(x)

y.date <- as.Date(paste(2006, 02, c(1, 3, 7, 9, 14), sep = "-"))
y <- zoo(matrix(11:20, ncol = 2), y.date)
y
str(y)
#
On Fri, Oct 15, 2010 at 2:20 PM, Megh Dal <megh700004 at yahoo.com> wrote:
If I try it then it works properly so there is likely something wrong
with your dat11 and dat22 objects.  If you provide the problem
reproducibly one might be able to say more.
+ 2010-10-15 13:43:54 73.8 73.8 73.8 73.8
+ 2010-10-15 13:44:15 73.8 73.8 73.8 73.8
+ 2010-10-15 13:45:51 73.8 73.8 73.8 73.8
+ 2010-10-15 13:46:21 73.8 73.8 73.8 73.8
+ 2010-10-15 13:47:27 73.8 73.8 73.8 73.8
+ 2010-10-15 13:47:54 73.8 73.8 73.8 73.8
+ 2010-10-15 13:49:51 73.7 73.7 73.7 73.7"
+ 2010-10-15 12:09:12 74.0 74.0 74.0 74.0
+ 2010-10-15 12:09:33 73.9 73.9 73.9 73.9
+ 2010-10-15 12:20:36 74.0 74.0 74.0 74.0
+ 2010-10-15 12:30:36 74.0 74.0 74.0 74.0
+ 2010-10-15 12:41:03 73.7 73.7 73.7 73.7"
+ index = list(1, 2), FUN = function(d, t) as.POSIXct(paste(d, t)))
Warning messages:
1: closing unused connection 8 (Lines2)
2: closing unused connection 7 (Lines1)
3: closing unused connection 5 (Lines2)
4: closing unused connection 4 (Lines1)
5: closing unused connection 3 (Lines2)
+ index = list(1, 2), FUN = function(d, t) as.POSIXct(paste(d, t)))
V2.dat1 V3.dat1 V4.dat1 V5.dat1 V2.dat2 V3.dat2
V4.dat2 V5.dat2
2010-10-15 12:09:12      NA      NA      NA      NA    74.0    74.0
74.0    74.0
2010-10-15 12:09:33      NA      NA      NA      NA    73.9    73.9
73.9    73.9
2010-10-15 12:20:36      NA      NA      NA      NA    74.0    74.0
74.0    74.0
2010-10-15 12:30:36      NA      NA      NA      NA    74.0    74.0
74.0    74.0
2010-10-15 12:41:03      NA      NA      NA      NA    73.7    73.7
73.7    73.7
2010-10-15 13:43:54    73.8    73.8    73.8    73.8      NA      NA
  NA      NA
2010-10-15 13:44:15    73.8    73.8    73.8    73.8      NA      NA
  NA      NA
2010-10-15 13:45:51    73.8    73.8    73.8    73.8      NA      NA
  NA      NA
2010-10-15 13:46:21    73.8    73.8    73.8    73.8      NA      NA
  NA      NA
2010-10-15 13:47:27    73.8    73.8    73.8    73.8      NA      NA
  NA      NA
2010-10-15 13:47:54    73.8    73.8    73.8    73.8      NA      NA
  NA      NA
2010-10-15 13:49:51    73.7    73.7    73.7    73.7      NA      NA
  NA      NA
#
I have compared "dat11" and "x" using str() function, however did not find
drastic difference:
?zoo? series from 2010-10-15 13:43:54 to 2010-10-15 13:49:51
  Data: num [1:7, 1:4] 73.8 73.8 73.8 73.8 73.8 73.8 73.7 73.8 73.8 73.8 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:7] "7" "6" "5" "4" ...
  ..$ : chr [1:4] "V2" "V3" "V4" "V5"
  Index:  POSIXlt[1:7], format: "2010-10-15 13:43:54" "2010-10-15 13:44:15"
"2010-10-15 13:45:51" "2010-10-15 13:46:21" "2010-10-15 13:47:27"
"2010-10-15 13:47:54" ...
?zoo? series from 2003-02-01 to 2003-02-14
  Data: int [1:5, 1:2] 1 2 3 4 5 6 7 8 9 10
  Index: Class 'Date'  num [1:5] 12084 12086 12090 12092 12097

Thanks,