-3

I have some problems with time-series designation of vectors in R.

I work with time-series and when I want to set a vector to a certain period, I feel quite confident about how to do it. I have simply done as follow name<- ts(name, frequency=12, start=c(2007,1)). As you can see I have monthly data

I am making an R template for colleagues to use, and I want them to be able to carry out a recursive ARIMA regression from any given starting point. That is, I have a range of in-sample predicted valued and I want to designate a start-value that is n monthly observation after 2007 (or whatever start data is used), where n is the start-value of the recursive regression.

pkpkPPkafa
  • 13
  • 2
  • 11
  • 2
    What is exactly your question? What did you try yourself? Basically, [How to make a great R reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – StatMan Aug 22 '16 at 11:47

1 Answers1

0

first and last from the xts time-series package do exactly what you want.i.e. to get the first 2 months of an object x:

first(x, '2 months’)

or the last 6 weeks:

last(x, '6 weeks’)

Valid period.types are: secs, seconds, mins, minutes, hours, days, weeks, months, quarters, and years. As always you can find much more detailed information using ?xts::first.

hvollmeier
  • 2,956
  • 1
  • 12
  • 17
  • Hey. Thanks for your response. My vector is a vector of predictions. Because of have partitioned my time series vector into a training set and a test set, the prediction vector goes from 85:113 (the 29 values of my test set). Note, however, I want to be able to change the length of the test set. I want to plot these predictions alongside the observed values, which are a time-series, thus the former should be turned into a time series. So I tried to use `name<- ts(name, frequency=12, start=c(2007,1))` , but don't know how to add the length of my training set in months to the start date. – pkpkPPkafa Aug 23 '16 at 07:49
  • Please let me know, if there is any part that is unclear. – pkpkPPkafa Aug 23 '16 at 07:51
  • I am afraid I can not be of much help regarding your comment as I use the `xts` and `zoo` packages for my research with time series and have `timeseries` not installed. Have you tried `as.ts` to convert to ts-object ? – hvollmeier Aug 23 '16 at 08:11