[R] Help with a code in R

Mark Sharp msharp at txbiomed.org
Tue Sep 6 05:47:25 CEST 2016


Erika,

You have failed to supply reproducible code. I do not all that is missing, but a glance shows that you did not include the code to load the foreach package or a definition of the objects named comb and b.

It is very likely you will receive assistance if you can follow the posting guide http://www.R-project.org/posting-guide.html


Mark

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msharp at TxBiomed.org







> On Sep 5, 2016, at 1:25 PM, Erika Rocío Espinosa Balbuena <erikareb at gmail.com> wrote:
>
> 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]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments transmitted, may contain privileged and confidential information and is intended solely for the exclusive use of the individual or entity to whom it is addressed. If you are not the intended recipient, you are hereby notified that any review, dissemination, distribution or copying of this e-mail and/or attachments is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender stating that this transmission was misdirected; return the e-mail to sender; destroy all paper copies and delete all electronic copies from your system without disclosing its contents.


More information about the R-help mailing list