I don't have your dataset, but this should work:
set.seed(22)
sales <- data.frame(Article_ID = letters[1:6])
sales[paste0("Week", 1:9)] <- replicate(9, rpois(6, 100))
sales
# Article_ID Week1 Week2 Week3 Week4 Week5 Week6 Week7 Week8 Week9
# 1 a 94 98 126 98 84 86 110 89 95
# 2 b 100 98 92 102 95 88 132 85 92
# 3 c 105 103 108 94 106 93 98 92 89
# 4 d 106 92 120 104 94 105 103 99 98
# 5 e 96 108 109 96 104 107 88 116 91
# 6 f 99 114 83 108 108 119 102 91 125
sales_ts <- ts(
t(sales[, -1]),
frequency = 52,
class = c("mts", "ts", "matrix")
)
rownames(sales_ts) <- names(sales)[-1]
colnames(sales_ts) <- sales[["Article_ID"]]
sales_ts
# Time Series:
# Start = c(1, 1)
# End = c(1, 9)
# Frequency = 52
# a b c d e f
# 1.000000 94 100 105 106 96 99
# 1.019231 98 98 103 92 108 114
# 1.038462 126 92 108 120 109 83
# 1.057692 98 102 94 104 96 108
# 1.076923 84 95 106 94 104 108
# 1.096154 86 88 93 105 107 119
# 1.115385 110 132 98 103 88 102
# 1.134615 89 85 92 99 116 91
# 1.153846 95 92 89 98 91 125
The key part is this:
sales_ts <- ts(
t(sales[, -1]),
frequency = 52,
class = c("mts", "ts", "matrix")
)
t(sales[, -1]) takes the sales dataset, omits the first column ("Article_ID"), and transposes it so the rows become columns. The resulting dataset is then turned into a time series with frequency of 52. The class = c("mts", "ts", "matrix") part tells the ts() function to make a "matrix time series," where each column is a separate time series. You can read about with help("ts").
Note for the future: To format a code block on this forum, wrap the code lines between two lines of three accent marks:
```
# Formatted like code
1 * 1 + 1 * 1
```
Also, when just sharing a single data object, you can see the code to recreate it with dput(myobject). Just share that code with others for a quick-and-dirty reprex.