[R] Help with a code in R
Erika Rocío Espinosa Balbuena
erikareb at gmail.com
Mon Sep 5 20:25:42 CEST 2016
Hi,
I am working with this code:
forecast_nal<-data.frame()
out<-vector()
x<-foreach(i=1:nrow(comb)) %do%
{
s<-comb[i,'prod_id']
#Familia+Sumbarca+prod_id
#Serie
bcomb1<-b
bcomb1<-subset(bcomb1,bcomb1$prod_id == s & bcomb1$year <= 2015)
bcomb1<-arrange(bcomb1,year,week)
a<-bcomb1[1:1,'week']
d<-bcomb1[1:1,'year']
f<-nrow(bcomb1)
h<-bcomb1[f:f,'year']
j<-bcomb1[f:f,'week']
bcomb1<-bcomb1[,c(6)]
if (length(bcomb1)<=10 || h=="2014" || (h=="2015" && j<=48))
{
out[i]<-s
}
else
{
y <- ts(bcomb1, frequency=52, start=c(d, a))
##Casos
if (length(y)<=60)
{
v<-auto.arima(y)
v<-arimaorder(v)
fit <- arima(y, order = v ,method="ML")
fca <- forecast(fit, h = 16)
dates <- attr(forecast_nal$mean, "tsp")
datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
fct<-cbind.data.frame(s,datecol,Point=fca$mean)
forecast_nal<- rbind.data.frame(forecast_nal,fct)
}
else
{
fit <- tbats(y)
fcb <- forecast(fit, h = 16)
dates <- attr(forecast_nal$mean, "tsp")
datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
fct<-cbind.data.frame(s,datecol,Point=fcb$mean)
forecast_nal<- rbind.data.frame(forecast_nal,fct)
}
}
}
But I am getting this error:
Error in `[<-.ts`(`*tmp*`, ri, value = c(26656.136365833, 26750.9374514082,
:
only replacement of elements is allowed
Can someone help me with this?
Thanks
--
Erika Rocío Espinosa Balbuena
[[alternative HTML version deleted]]
More information about the R-help
mailing list