我正在尝试建立一个“ for”序列以生成具有相应公式对象的对象。我试图将其用于randomForest,一旦尝试将其应用于for循环中,我的方法都无法正常工作...
这是我编写的代码,它可以独立运行。
AWS.config.update()
TARGET_WEEK <- "12"
QTY_VARLIST <- list(paste0("max_qty ~ supply + season + item_grp + months"))
for(i in 1 : TARGET_WEEK) {
QTY_VARLIST[i+1] <- (paste0("+qty",i,"+sales_gr",i))
}
for(i in 2 : TARGET_WEEK) {
ifelse(as.numeric(TARGET_WEEK) < 2, QTY_VARLIST[as.numeric(TARGET_WEEK)+i] <- "",
QTY_VARLIST[as.numeric(TARGET_WEEK)+i] <- (paste0("+sal_ratio_",i)))
}
ifelse(as.numeric(TARGET_WEEK) < 2, QTY_VARLIST[as.numeric(TARGET_WEEK)+13] <- "", QTY_VARLIST[as.numeric(TARGET_WEEK)+13] <- paste0("+sales_rate_dif",i))
ifelse(as.numeric(TARGET_WEEK) < 2, QTY_VARLIST[as.numeric(TARGET_WEEK)+14] <- "", QTY_VARLIST[as.numeric(TARGET_WEEK)+14] <- paste0("+sales_speed",i))
QTY_VARLIST[QTY_VARLIST=='NULL'] <- ""
QTY_VARLIST<-as.character(unite(as.data.frame(QTY_VARLIST),sep = ""))
#QTY_VARLIST<-as.formula(QTY_VARLIST)
assign(paste0("QTY_VARLIST_",TARGET_WEEK,"W"),as.formula(QTY_VARLIST))
我想做的是,如果我可以使用TARGET_WEEK从2到12申请循环,那么它就一直停留在中间,并永远运行下去。我想要的是:
> QTY_VARLIST_12W
max_qty ~ supply + season + item_grp + months + qty1 + sales_gr1 +
qty2 + sales_gr2 + qty3 + sales_gr3 + qty4 + sales_gr4 +
qty5 + sales_gr5 + qty6 + sales_gr6 + qty7 + sales_gr7 +
qty8 + sales_gr8 + qty9 + sales_gr9 + qty10 + sales_gr10 +
qty11 + sales_gr11 + qty12 + sales_gr12 + sal_ratio_2 + sal_ratio_3 +
sal_ratio_4 + sal_ratio_5 + sal_ratio_6 + sal_ratio_7 + sal_ratio_8 +
sal_ratio_9 + sal_ratio_10 + sal_ratio_11 + sal_ratio_12 +
sales_rate_dif12 + sales_speed12
高达12W的单个“ for”循环,全部存储在我的内存中。
您能帮我吗?