循环执行时返回错误的函数

时间:2017-12-18 11:58:07

标签: r list time-series

我有以下功能:

funNNET <- function(dFrame,nDF,horizon,i,j){
       model_NNET <- forecast::nnetar(y = dFrame$Qty)

## Dataframe with predictions ##

  output_nnet <- list()
  output_nnet$Sales_Date = nDF$Sales_Date
  output_nnet$predNNET = as.integer(forecast(object = model_NNET, h = 
  horizon)$mean)
  output_nnet$LastYear = nDF$LastYear
  output_nnet$Combi = paste(i,j,sep = "|")

  print(output_nnet$predNNET)
  return(output_nnet)
}

当我单独执行此函数时,它运行完美,我得到了我的结果列表。但是,当我在循环中执行此函数时(比如foreach或lapply),我只得到一个日期列表,这是我所需输出列表的第一项。

请帮助我找到我所缺少的东西。如果需要任何信息,请告诉我,我会分享。

更新

使用以下命令获取样本数据集

dFrame <- data.frame(Sales_Date = seq(as.Date("2017-12-12"),as.Date("2017-
12-30"),"days"),
Qty = c(rep(3.4,5),rep(4.2,1),rep(4.9,3),rep(3,2),rep(5.6,5),rep(7.2,3)) )

nDF <- data.frame(Sales_Date = seq(min(dFrame$Sales_Date) - 
lubridate::years(1) ,max(dFrame$Sales_Date) - lubridate::years(1),"days"),
LastYear 
=c(rep(9.4,5),rep(2.5,1),rep(6.2,3),rep(3.1,2),rep(9.5,5),rep(11.1,3)) )

horizon = 30

i = c("AHMD","BLR","MUM","DEL")
j = c("A","B","C","D")

0 个答案:

没有答案