Source Prediction Packet R

I use the forecast package and save the results

t <- data.frame(forecast(prod.arima, h=4)) 

to the data frame. Line names are my dates, which when printed look like

 > t Point.Forecast Lo.80 Hi.80 Lo.95 Hi.95 2010.856 812.9849 630.5707 995.3992 534.0064 1091.9634 2010.876 670.3363 485.1885 855.4840 387.1772 953.4953 2010.895 769.4848 584.2552 954.7145 486.2005 1052.7691 2010.914 692.8951 507.6630 878.1272 409.6070 976.1832 

I do not close (for now) to complete this, but I hope to automate the LaTex report, where I will print forecasts on the report page and forecast graph. I believe that I can pass the dataframe to the LaTex table, but I need the dates to be formatted so that the end user understands that they represent the weekend (set on Sundays).

I converted the original time series with readable dates to a time series object using

 ts(prod, start = 2009 +(31+28+31+5)/365, f=52 ) 

where the start of my deadlines was April 5, 2009 and provided weekly data.

Any help you can provide would be greatly appreciated. Needless to say, I'm pretty new to R.

+4
source share
1 answer

I can think of two ways: one could use the as.Date.cal.yr function from the Epi package. Another would be to multiply these dates by the number of seconds per year, and then pass this to as.POSIXct (but I have not tested this.) Of these two, the first seems the least painful:

 require(Epi) as.Date.cal.yr(as.numeric(row.names(t))) # [1] "2010-11-10" "2010-11-17" "2010-11-24" "2010-12-01" as.POSIXlt(as.Date.cal.yr(as.numeric(row.names(t))))$wday # [1] 3 3 3 3 paste(weekdays(as.Date.cal.yr(as.numeric(row.names(t)))) , as.Date.cal.yr(as.numeric(row.names(t))), sep=",") # [1] "Wednesday,2010-11-10" "Wednesday,2010-11-17" "Wednesday,2010-11-24" # [4] "Wednesday,2010-12-01" 

So, I do not get Sunday, since it will be wday == 0 on the POSIXlt system. See Help for DateTimeClasses.

Regarding the LaTeX part of the question, install the Hmisc package and use the latex () function.

+4
source

All Articles