I have a list containing 15 data frames.
> head(forecast_ucmseasonality)
$us_month_businessconfidence
[1] 52.45713 53.49713 52.97712 53.15715 52.81716 52.75717 52.48875 53.00550 52.97213 52.77213
[11] 52.03886 52.33882
$us_month_chainstoresales
[1] 4099.952 4592.386 4195.608 4518.860 6230.274 9649.281 3373.654 3837.009 4417.476 4421.007
[11] 4857.800 4181.440
$us_month_cpi
[1] 235.905 236.223 236.575 237.335 237.890 238.772 239.448 239.241 239.313 239.363 239.250
[12] 239.159
This list was UCM result on another list. I have applied a condition to reduce large input values
train_dataucm <- lapply(train_data, transform, Value = ifelse(Value > 50000 , Value/100000 , Value )) #reducing large values in order for the UCM function to work
ucm_trainseasonality <- lapply(train_dataucm, function(x) ucm(Value~0,data = x , level=T, irregular=T,slope=T,season=T,season.length=12))
forecast_ucmseasonality <- lapply(ucm_trainseasonality, function(x) predict(x, n.ahead = 12))
The initial list looks like this :
head(train_data[[5]])
DateTime Value
721 2010-01-31 138438
722 2010-02-28 138581
723 2010-03-31 138751
724 2010-04-30 139297
725 2010-05-31 139241
726 2010-06-30 139141
I am specifically showing you the 5th element in the list because it was the one which got affected because of having large values.
Also, I am identifying this data frame from the list using the following function :
has_too_high_values <- function (df)
any(df$Value > 50000)
identify_val <- Filter(has_too_high_values, train_data)
> identify_val
$us_month_employedppl
DateTime Value
721 2010-01-31 138438
722 2010-02-28 138581
723 2010-03-31 138751
724 2010-04-30 139297
725 2010-05-31 139241
726 2010-06-30 139141
727 2010-07-31 139179
PROBLEM:
I want to use the list
identify_val
to identify the elements in forecast_ucmseasonality
list
which will be multiplied by 100000 so that I get the correct forecasted values.
My sample code should look something like this:
forecast_ucmseasonality <- lapply(forecast_ucmseasonality, function(x) ifelse(names(forecast_ucmseasonality) == names(identify_val) , x$Value*100000, x$Value)
I hope I am clear in my question.
Thank You.