-1

I have a 3000 x 1000 matrix time series database going back 14 years that is updated every three months. I am forecasting out 9 months using this data still keeping a 3200 x 1100 matrix (mind you these are rough numbers).

During the forecasting process I need the variables Year and Month to be calculated appropriately . I am trying to automate the process so I don't have to mess with the code any more; I can just run the code every three months and upload the projections into our database.

Below is the code I am using right now. As I said above I do not want to have to look at the data or the code just run the code every three months. Right now everything else is working as planed, but I still have to ensure the dates are appropriately annotated. The foo variables are changed for privacy purposes due to the nature of their names.

projection <- rbind(projection, data.frame(foo=forbar, bar=barfoo, 
+                                                    Year=2012, Month=1:9, 
+                                                    Foo=as.vector(fc$mean)))
user247702
  • 23,641
  • 15
  • 110
  • 157
j riot
  • 544
  • 3
  • 6
  • 16
  • It seems to me very unclear what you are asking. What exactly is the problem? You didn't provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so it's not easy to see what is currently happening and what you would ideally like to happen. Consider editing your question to be more specific. You don't have to use "real" data, but you should use "some" data. – MrFlick May 28 '14 at 17:54
  • I am new to R and StackOverflow, I don't know how to exactly post a data example. The matrix portion is not important. I have data from Jan 2001 to Jan 2012 which columns labelled SP500 (example), Year and Month. I am running an ARIMA model to forecast the SP500 9 months ahead. Yet, I want it to print the Year and Month as well with the appropriate forecast- 1500 2012 01, 1525 2012 02 etc. The coding prints 2012 because I told it and the month because I told it yet when the data is updated I will need to alter that code to ensure the appropriate dates are being printed. How, do I automate it? – j riot May 28 '14 at 18:13
  • I have data from Jan 2001 to Jan 2011*** Not 2012 as stated. – j riot May 28 '14 at 18:26
  • It's best to edit your original question to add more information than to put a lot of stuff in comments. I provided a link in my original comment showing how to share sample data sets. But you can find the current date and the next 9 months with `seq.Date(from=Sys.Date(), by="months", length.out=10)`. Or see if @nfmcclure's answer is what you are after. It's difficult to help you automate code we can't see. – MrFlick May 28 '14 at 18:32

1 Answers1

0

I'm not sure exactly where the year/months are coming from, but if you want to refer to the current date for those numbers, here is an option (using the wonderful package, lubridate):

library(lubridate)
today = Sys.Date()
projection <- rbind(projection, data.frame(foo=foobar, bar=barfoo,
                                       year = year(today),
                                       month = sapply(1:9,function(x) month(today+months(x))),
                                       Foo = as.vector(fc$mean)))

I hope this is what you're looking for.

nfmcclure
  • 3,011
  • 3
  • 24
  • 40