[R] Time series (ts) questions.

Gabor Grothendieck ggrothendieck at gmail.com
Mon Sep 22 17:01:58 CEST 2008


Try this to append 100 to the end of the series, say:

tt <- ts(1:12, frequency=5) # sample data
ts(c(tt, 100), start = start(tt), frequency = frequency(tt))


On Mon, Sep 22, 2008 at 2:17 AM,  <rkevinburton at charter.net> wrote:
> 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.
>
> Kevin
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list