Forecasting time series data

Here’s what I did: x$Date = as.Date(x$Date,format=”%m/%d/%Y”) x = xts(x=x$Used, order.by=x$Date) # To get the start date (305) # > as.POSIXlt(x = “2011-11-01″, origin=”2011-11-01”)$yday ## [1] 304 # Add one since that starts at “0” x.ts = ts(x, freq=365, start=c(2011, 305)) plot(forecast(ets(x.ts), 10)) Resulting in: What can we learn from this: Many of your steps … Read more

Basic lag in R vector/dataframe

I had the same problem, but I didn’t want to use zoo or xts, so I wrote a simple lag function for data frames: lagpad <- function(x, k) { if (k>0) { return (c(rep(NA, k), x)[1 : length(x)] ); } else { return (c(x[(-k+1) : length(x)], rep(NA, -k))); } } This can lag forward or … Read more