Skip to content

R: ts - objects (PR#228)

2 messages · Peter Dalgaard, Martyn Plummer

#
Marcus Eger <marcus.eger@physik.uni-marburg.de> writes:
Looks like a bug...
Yes, we discussed that a short while ago on R-devel. It's trying too
hard to retain the ts attributes in these cases.
...although range(x,finite=T) is probably a better fix.
or just:
Time Series:
Start = c(3, 1) 
End = c(7, 1) 
Frequency = 0.666666666666667 
Error: invalid start

..which is pretty darn weird! CC'ed to R-bugs.
#
That's just the print method for ts objects calling
time().

The underlying problem is in start().
[1] 3 1

I think the 2-vector form of start and end only makes sense when the
frequency is an integer. If I am right then the following versions of
start.ts and end.ts (which check that tsp[3] is an integer) should solve
the problem.

M.

"start.ts" <- function (x) 
{
    ts.eps <- .Options$ts.eps
    ##if(is.null(ts.eps)) ts.eps <- 1.e-5
    tsp <- attr(as.ts(x), "tsp")
    is <- tsp[1] * tsp[3]
    if (abs(tsp[3] - round(tsp[3])) < ts.eps && abs(is - round(is)) < 
        ts.eps) {
        is <- floor(tsp[1])
        fs <- floor(tsp[3] * (tsp[1] - is) + 0.001)
        c(is, fs + 1)
    }
    else tsp[1]
}

"end.ts" <- function(x)
{
    ts.eps <- .Options$ts.eps
    ## if(is.null(ts.eps)) ts.eps <- 1.e-5
    tsp <- attr(as.ts(x), "tsp")
    is <- tsp[2] * tsp[3]
    if (abs(tsp[3] - round(tsp[3])) < ts.eps && abs(is - round(is)) < 
        ts.eps) {
        is <- floor(tsp[2])
        fs <- floor(tsp[3] * (tsp[2] - is) + 0.001)
        c(is, fs + 1)
    }
    else tsp[2]
}

M.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._