[Rd] Ops.ts returns non-ts object for univariate operations (PR#7152)

jpalmucci at machineinsight.com jpalmucci at machineinsight.com
Tue Aug 3 18:07:37 CEST 2004


Full_Name: Jeff Palmucci
Version: 1.9.1
OS: XP
Submission from: (NULL) (129.44.190.60)


Ops.ts returns a non-time series object for univariate operations. Here is a
patch:

Ops.ts <- function(e1, e2)
{
    if(missing(e2)) {
        ## univariate operator
      result <- NextMethod(.Generic)
      attributes(result) <- attributes(e1)
      result
    } else if(any(nchar(.Method) == 0)) {
        ## one operand is not a ts
        NextMethod(.Generic)
    } else {
        nc1 <- NCOL(e1)
        nc2 <- NCOL(e2)
        ## use ts.intersect to align e1 and e2
        e12 <- .cbind.ts(list(e1, e2),
                         c(deparse(substitute(e1))[1],
                           deparse(substitute(e2))[1]),
                         union = FALSE)
        e1 <- if(is.matrix(e1)) e12[, 1:nc1, drop = FALSE] else e12[, 1]
        e2 <- if(is.matrix(e2)) e12[, nc1 + (1:nc2), drop = FALSE]
        else e12[, nc1 + 1]
        NextMethod(.Generic)
    }
}



More information about the R-devel mailing list