Hi,

I have two questions about ts.

(1) How do I subset a ts object and still preserve the time index? for
example:

> x=ts(1:10, frequency = 4, start = c(1959, 2)) # the ts object
> x
     Qtr1 Qtr2 Qtr3 Qtr4
1959         1    2    3
1960    4    5    6    7
1961    8    9   10
I don't want the 1st 2 elements, so I could subset like this:
> x[3:length(x)]
[1]  3  4  5  6  7  8  9 10

But then the time index is lost. I could use window(), but then I have to
specify start and end manually. Is there a way to subset a ts object so that
the time index is preserved for the data extracted without specifying start
and end data by hand?

(2) How do I join two ts objects together end to end? for example:
> x=ts(1:10, frequency = 4, start = c(1959, 2)) # the 1st ts object
> y=ts(11:15, frequency = 4, start = c(1961, 4)) # the 2nd ts object

As you can see, y is just a continuation of x. I would like to add y to the
end of x while preserving the time index. I could use this:
> ts(c(x,y),start=start(x),frequency=4)

But I am wondering if there is a more efficient way of doing this, i.e., is
it really necessary to specify start and frequency again when they are
already a part of the original ts objects?

Thanks!

-- 
Tom

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to