Hello I have two times series for the same asset. Unfortunately, the series
with the most history has been discontinued. I want to combine the old
series with the new one in a new zoo object. I tried combining them using
ifelse, but the result is a vector, not a zoo object. In other words, I lost
the dates in the process.

How do I get the result in a zoo object?

Here's my attempt:



#build series for reproducible example

z <- zoo(matrix(1:20,ncol=2),

     as.Date(c("1992-01-10", "1992-01-17", "1992-01-24", "1992-01-31",

       "1992-02-07", "1992-02-14", "1992-02-21", "1992-02-28", "1992-03-06",

       "1992-03-13")))

z[1:5,1] <-NA

z[8:10,2] <-NA



#initial series with imcompletes

z



#my function

bc.combine <-function(imcomplete.1,fill.with.2){

res <-ifelse(!is.na(imcomplete.1),imcomplete.1,fill.with.2)

return(res)

}



#two zoo objects as inputs but the result is a vector

bc.combine(z[,2,drop=F],z[,1,drop=F])



      [,1]

 [1,]   11

 [2,]   12

 [3,]   13

 [4,]   14

 [5,]   15

 [6,]   16

 [7,]   17

 [8,]    8

 [9,]    9

[10,]   10

	[[alternative HTML version deleted]]

