Require help in holt winter model forecasting by a new R user

Hi all,
This is my first post in this forum. I seek advice from the learned members of this community. I am a new and inexperienced user to the R language.
My goal: Generate a forecast using holt winters model for around 50 items. Each item has last 2 years data on a weekly basis.
I will take only those items where the sales qty is big (like 30, 40 a week and not 2,3,5 units a week) so that I get a trend from the data.
Input: I have the sales data in excel, both item ID, sales qty, time frame as week (can be done in days as well).
I have a particular set of code, which my predecessor used here, who is longer associated with the firm.
However, the code is not running and I am not sure about the bug as well.
Here is the code snippet. Any help will be appreciated. TIA.

PS: Not able to add the R code here, every time it shows,

Hi, welcome!

We don't really have enough info to help you out. Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

If you've never heard of a reprex before, you might want to start by reading this FAQ:

Hi, thanks for the reply.

Here I am trying to post the code snippet, which is a legacy code, I want to import the sales data which is arrange in the excel each row represents each week. Have 52 weeks data.
Now, I want to see the forecast for the next weeks, using holt winters algo. But not sure if this code snippet is correct syntax wise and structure wise.

rm(list = ls())

#set directory

# load required packages

# import data
sales <- read_csv("sample_sale_data.csv")

# examine dataset
head(sales, n = 5)

# convert our sales data to a time series object
salesTS <- ts(sales$Rec_goods, frequency = 12, start = c(2016,1))
# afgts <- ts(myvector, start=c(2016, 1), end=c(2016, 52), frequency=52)

# Plot
options(repr.plot.width = 6, repr.plot.height = 5)
salesDecomp <- decompose(afgts)

# log transform time series data
salesLogHW <- HoltWinters(afgts)

options(repr.plot.width = 6, repr.plot.height = 4)

# forecast next year's sales
nxtQtrSales <- forecast(salesLogHW, h=13)

# plot

write.csv(nxtQtrSales,"forecast_sales.csv",row.names = FALSE)


You usually need 2 years of data to use Holt Winters....

Your periodicity should be 52, not 12 as you have weekly data.

Double Exponential Smoothing would probably be a better choice for you...

Best regards,

Hi Rudolph,
Many thanks for your input. So, I have run the code, and yes updated the frequency as 52. I have sales data of 3 years. So, i think it is reading 3 years weekly data. and predicting the forecast for next 13 weeks.

Now, coming to my new question:
I have around 17,000 SKUs/Items for which I need to prepare the forecast at once. Here, this code is only reading the agregate sales qty week wise and giving me the forecast. How do I enforce it to give me forecast of each SKU?
Can I use any loop (I used for loop in Java, long back)?
basically my data set has 3 major parameters. 1 SKU/Item ID, 2 Time frame. 3. sales qty in units.

Thanks all.

You can nest your dataset by SKU and use purrr::map() to fit a model and make predictions for each group, if you need specific help with this, please provide a proper reproducible example including sample data (as explained in the link I gave you before).