Skip to content
Prev 165123 / 398513 Next

For and if confusion

Here is a solution that only uses ts (no zoo) starting from
the dates:

fmt <- "%d-%m-%Y"
X <- as.Date(c("01-03-1993", "01-05-1997"), fmt)
Y <- as.Date(c("01-02-1995", "01-08-1999"), fmt)

ym <- function(x) with(as.POSIXlt(x), c(1900 + year, mon+1))

Xt <- ts(1, start = ym(X[1]), end = ym(X[2]), freq = 12)
Xt <- ts(1, start = ym(Y[1]), end = ym(Y[2]), freq = 12)

Xt2 <- cbind(Xt, A)[, 1]
Yt2 <- cbind(Yt, A)[, 1]

Xt2[is.na(Xt2)] <- 0
Yt2[is.na(Yt2)] <- 0

pmax(Xt2, Yt2)


On Thu, Dec 18, 2008 at 10:05 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote: