View source: R/lmForc_transform.R
convert_bytime | R Documentation |
Given a list of forecasts with different h_ahead values, converts the forecasts to time format based on the time object passed to the values argument. Converts Forecast objects that have have homogenous h_ahead values to Forecast objects with homogenous origin or future values.
convert_bytime(forcs, values, slot)
forcs |
List of Forecast objects. |
values |
Single time object or a vector of time objects. |
slot |
Character representing whether the list of Forecasts will be converted to homogenous origin or future values. Must be either "origin" or "future". |
Single Forecast object or list of Forecast objects in time format.
# The following forecasts are in h_ahead format. All forecasts come from the
# same source (forc1) and have the same origin values. However, the forecasts
# are for different periods ahead.
forc1_1h <- Forecast(
origin = as.Date(c("2010-02-17", "2010-05-14", "2010-07-22", "2010-12-22")),
future = as.Date(c("2010-06-30", "2010-09-30", "2010-12-31", "2011-03-31")),
forecast = c(4.27, 3.36, 4.78, 5.45),
realized = c(4.96, 4.17, 4.26, 4.99),
h_ahead = 1
)
forc1_2h <- Forecast(
origin = as.Date(c("2010-02-17", "2010-05-14", "2010-07-22", "2010-12-22")),
future = as.Date(c("2010-09-30", "2010-12-31", "2011-03-31", "2011-06-30")),
forecast = c(3.77, 3.82, 4.53, 4.89),
realized = c(4.17, 4.26, 4.99, 5.33),
h_ahead = 2
)
forc1_3h <- Forecast(
origin = as.Date(c("2010-02-17", "2010-05-14", "2010-07-22", "2010-12-22")),
future = as.Date(c("2010-12-31", "2011-03-31", "2011-06-30", "2011-09-30")),
forecast = c(3.52, 4.22, 5.03, 5.78),
realized = c(4.26, 4.99, 5.33, 5.21),
h_ahead = 3
)
forcs <- list(forc1_1h, forc1_2h, forc1_3h)
convert_bytime(forcs, value = as.Date("2010-05-14"), slot = "origin")
convert_bytime(
forcs,
value = as.Date(c("2010-07-22", "2010-12-22")),
slot = "origin"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.