I want to coduct a forecast analysis on my dataset. Some insights into the dataset:

  • I have 10 Products each having a specific Id Number. These numbers are random and dont have any pattern.
  • Each product has data starting from the year 2016 till 2018 for each month. So, 36 Observation Points for each product.

All these products are present in a single dataset in the column format and a total of 300 rows (certain products have missing data):

Column names: Prod_Id Year Month Sales_data

Would appreciate a guidance on the optimal approach that can be taken?

I am thinking of the following:

  • Create a new vector with the unique Product_Ids and use its length to create a Loop
  • Perform the forecast Analysis for one of the products and contain it in a Loop for other variables.

I am absolutely new to R and would appreciate any help/suggestions.

Dataset with more than one variable to be forecasted


it is very difficult to give an answer without a glimpse of your data, but here is my approach:

Inside your loop

  1. Create a time series ts for the data of each product: myts <- ts(mydata_for_product_i, start=c(2016, 1), end=c(2018, 12), frequency=12)
  2. Apply your forescast analysis to each mytsinside the loop and store them in a list.

A fancier way to do would be using fuctions oof the apply family, but without having the structure of your data I cannot produce any code I am sure to work

  • $\begingroup$ Hey, thanks a lot! I am attaching a sample dataset. Here you can see only 2 product Id. But in the actual dataset I have many more. Also, please note, certain month's values are missing for each product. For example Product_id 10 has missing values for 2017, month 3 to 5. $\endgroup$ – user10579790 Feb 11 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.