t() of a time series (PR#1998)

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Tue, 17 Sep 2002 10:11:46 +0200


>>>>> "PaulG" == Paul Gilbert <pgilbert@bank-banque-canada.ca>
>>>>>     on Tue, 10 Sep 2002 15:54:58 +0200 (MET DST) writes:

    PaulG> (In R 1.5.1 ) t() preserves time series attributes
    PaulG> but not ts structure:

    >> xmat2 <- ts(matrix(rnorm(100),ncol=2)) end(t(xmat2))
    PaulG>  [1] 50 1 # this implies 50 periods of data
    >> dim(t(xmat2))
    PaulG>  [1] 2 50 # this implies 2 periods of data on 50
    PaulG> series

    PaulG> The time attributes and ts class should be removed by
    PaulG> t().

yes.

The following seems a cautious solution:

t.ts <- function(x) {
    cl <- class(x)
    other <- !(cl %in% c("ts","mts"))
    class(x) <- if(any(other)) cl[other]
    attr(x, "tsp") <- NULL
    t(x)
}

---
It passes "make check" and I plan to commit as bug fix to  
R (beta) 1.6.0.

Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._