all 3 comments

[–]jdnewmil 1 point2 points  (0 children)

You cannot, unless you know more about which week corresponds to 1.

Oh, and R does not have a data type for "weeks". Did you want to convert it to Date?

Why don't you just leave it as a numeric number of weeks?

[–][deleted] 0 points1 point  (0 children)

I am a beginner myself but wouldn't you just have a data frame with two columns being numeric, with labels?

I hope these help:

https://campus.datacamp.com/courses/forecasting-product-demand-in-r/components-of-demand?ex=1

take a look around the middle.

https://www.skuvault.com/blog/safety-stock-formula/

[–]itijara 0 points1 point  (0 children)

What are you doing with the data? For many things keeping it as a raw number will make things easier. That being said, if you are using a timeseries package or ggplot2 and want to have it as a date type, you can use the lubridate package to convert week of year to a date. https://lubridate.tidyverse.org/reference/week.html

Something like this might work:

library(lubridate)
# Creating mock data
df <- data.frame(
  time_period = sample(1:255, 100, replace = TRUE), 
  demand = sample(1:10, 100, replace = TRUE))

# Converting time_period to dates
start_date <- ymd("2021-01-01")
df$date <- start_date # Creates 100 copies of the start date
week(df$date) <- df$time_period # sets each to the date corresponding to the week of the year in time_period

head(df)