[R] Time series (ts) questions.

rkevinburton at charter.net rkevinburton at charter.net
Mon Sep 22 08:17:27 CEST 2008

I have been working with the base time series object (ts) and I had a couple of questions that hopefully this group can help me with:

1) What is the best why to append an observation to an existing time-series? Suppose I have a time series:

t <- ts(1:12, frequency=5)

This would generate two complete cycles and one remainder. Now I would like to append an observation to this time series. I could use 'c' but then I would need to rebuild the whole time series and I would need to know the frequency etc. I would like some operation like '+' that would simply append the value to the end of the time series (incrementing the 'las time value so thing like cycle() still output the correnct values) but alas

t + 10

is already taken as an equally useful operation by adding 10 to each element in the time series (rather than in thie case, appending ts(10,frequency) with a time value of 13 to the time series).

2) How is the best way to get the last time value in a time series? I can do something like:

(start(t)[2] - 1) + (end(t)[1]-1) * frequency(t) + end(t)[2]

But there has to be an easier way.

Thank you.


More information about the R-help mailing list