r - Error in if function -
i have run long script decide model should use forecast. after doing accuracy tests on in , out samples of data created large if function find model best results of either "arima", "arima.wgt", "addhw", "multhw", "addhwwgt" , "multhwwgt". during script have got forecasts each of these models , want use if function view them have written
if(maxmod<-"arima") modelf<-arimaaltfa else if(maxmod<-"arima.wgt") modelf<-arimaaltfb else if(maxmod<-"addhw") modelf<-hwabfc else if(maxmod<-"multhw") modelf<-hwmbfd else if(maxmod<-"addhwwgt") modelf<-hwaaltfe else modelf<-hwmaltff but keep getting error
error in if (maxmod <- "arima") modelf <- arimaaltfa else if (maxmod <- "arima.wgt") modelf <- arimaaltfb else if (maxmod <- "addhw") modelf <- hwabfc else if (maxmod <- "multhw") modelf <- hwmbfd else if (maxmod <- "addhwwgt") modelf <- hwaaltfe else modelf <- hwmaltff : argument not interpretable logical this has happened many different things have tried eg instead of modelf<-"" tried view("",title="") , modelf<-view("",title="") still saya isn't logical... there error in way have written or there problem?
extra detail , code available if needed
you need switch function.
modelf <- switch( maxmod, arima = arimaaltfa, arima.wgt = arimaaltfb, addhw = hwabfc, multhw = hwmbfd, addhwwgt = hwaaltfe, hwmaltff ) your specific problem trying assign values maxmod instead of comparing equality. although switch statement preferable, try replacing
if(maxmod<-"arima") with
if(maxmod == "arima") maxmod == "arima" returns true or false (a logical value).
maxmod<-"arima" assigns value "arima" variable named maxmod (and invisibly returns string).
Comments
Post a Comment