#Libraries Required
library(fpp2)
## Warning: package 'fpp2' was built under R version 3.5.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.5.3
## Loading required package: forecast
## Warning: package 'forecast' was built under R version 3.5.2
## Loading required package: fma
## Warning: package 'fma' was built under R version 3.5.2
## Loading required package: expsmooth
## Warning: package 'expsmooth' was built under R version 3.5.2
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.5.1
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(lubridate)
## Warning: package 'lubridate' was built under R version 3.5.1
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
library(readr)
## Warning: package 'readr' was built under R version 3.5.1
library(gridExtra)
## Warning: package 'gridExtra' was built under R version 3.5.3
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
library(urca)
## Warning: package 'urca' was built under R version 3.5.2
#Data Preparation
raw.data<- read.csv("C:\\Users\\nidhi\\OneDrive\\Desktop\\Forecasting project2\\Sales_Transactions_Dataset_Weekly.csv")
head(raw.data)
##   Product_Code W0 W1 W2 W3 W4 W5 W6 W7 W8 W9 W10 W11 W12 W13 W14 W15 W16
## 1           P1 11 12 10  8 13 12 14 21  6 14  11  14  16   9   9   9  14
## 2           P2  7  6  3  2  7  1  6  3  3  3   2   2   6   2   0   6   2
## 3           P3  7 11  8  9 10  8  7 13 12  6  14   9   4   7  12   8   7
## 4           P4 12  8 13  5  9  6  9 13 13 11   8   4   5   4  15   7  11
## 5           P5  8  5 13 11  6  7  9 14  9  9  11  18   8   4  13   8  10
## 6           P6  3  3  2  7  6  3  8  6  6  3   1   1   5   4   3   5   3
##   W17 W18 W19 W20 W21 W22 W23 W24 W25 W26 W27 W28 W29 W30 W31 W32 W33 W34
## 1   9   3  12   5  11   7  12   5   9   7  10   5  11   7  10  12   6   5
## 2   7   7   9   4   7   2   4   5   3   5   8   5   5   3   1   3   2   3
## 3  11  10   7   7  13  11   8  10   8  14   5   3  13  11   9   7   8   7
## 4   9  15   4   6   7  11   7   9   6  10  10   2   6   7   2   5  12   5
## 5  15   6  13  11   6  10   9   8  12   8   9  13   3   5   3   5   5   9
## 6   5  10   8   4   9   7   5   4   2   1   3   2   4   0   3   2  11   2
##   W35 W36 W37 W38 W39 W40 W41 W42 W43 W44 W45 W46 W47 W48 W49 W50 W51 MIN
## 1  14  10   9  12  17   7  11   4   7   8  10  12   3   7   6   5  10   3
## 2  10   5   2   7   3   2   5   2   4   5   1   1   4   5   1   6   0   0
## 3   9   6  12  12   9   3   5   6  14   5   5   7   8  14   8   8   7   3
## 4  19   8   6   8   8  12   6   9  10   3   4   6   8  14   8   7   8   2
## 5   7   4   8   8   5   5   8   7  11   7  12   6   6   5  11   8   9   3
## 6   1   4   4   3   2   5   4   4   2   4   3   6   5   3   3  10   6   0
##   MAX Normalized.0 Normalized.1 Normalized.2 Normalized.3 Normalized.4
## 1  21         0.44         0.50         0.39         0.28         0.56
## 2  10         0.70         0.60         0.30         0.20         0.70
## 3  14         0.36         0.73         0.45         0.55         0.64
## 4  19         0.59         0.35         0.65         0.18         0.41
## 5  18         0.33         0.13         0.67         0.53         0.20
## 6  11         0.27         0.27         0.18         0.64         0.55
##   Normalized.5 Normalized.6 Normalized.7 Normalized.8 Normalized.9
## 1         0.50         0.61         1.00         0.17         0.61
## 2         0.10         0.60         0.30         0.30         0.30
## 3         0.45         0.36         0.91         0.82         0.27
## 4         0.24         0.41         0.65         0.65         0.53
## 5         0.27         0.40         0.73         0.40         0.40
## 6         0.27         0.73         0.55         0.55         0.27
##   Normalized.10 Normalized.11 Normalized.12 Normalized.13 Normalized.14
## 1          0.44          0.61          0.72          0.33          0.33
## 2          0.20          0.20          0.60          0.20          0.00
## 3          1.00          0.55          0.09          0.36          0.82
## 4          0.35          0.12          0.18          0.12          0.76
## 5          0.53          1.00          0.33          0.07          0.67
## 6          0.09          0.09          0.45          0.36          0.27
##   Normalized.15 Normalized.16 Normalized.17 Normalized.18 Normalized.19
## 1          0.33          0.61          0.33          0.00          0.50
## 2          0.60          0.20          0.70          0.70          0.90
## 3          0.45          0.36          0.73          0.64          0.36
## 4          0.29          0.53          0.41          0.76          0.12
## 5          0.33          0.47          0.80          0.20          0.67
## 6          0.45          0.27          0.45          0.91          0.73
##   Normalized.20 Normalized.21 Normalized.22 Normalized.23 Normalized.24
## 1          0.11          0.44          0.22          0.50          0.11
## 2          0.40          0.70          0.20          0.40          0.50
## 3          0.36          0.91          0.73          0.45          0.64
## 4          0.24          0.29          0.53          0.29          0.41
## 5          0.53          0.20          0.47          0.40          0.33
## 6          0.36          0.82          0.64          0.45          0.36
##   Normalized.25 Normalized.26 Normalized.27 Normalized.28 Normalized.29
## 1          0.33          0.22          0.39          0.11          0.44
## 2          0.30          0.50          0.80          0.50          0.50
## 3          0.45          1.00          0.18          0.00          0.91
## 4          0.24          0.47          0.47          0.00          0.24
## 5          0.60          0.33          0.40          0.67          0.00
## 6          0.18          0.09          0.27          0.18          0.36
##   Normalized.30 Normalized.31 Normalized.32 Normalized.33 Normalized.34
## 1          0.22          0.39          0.50          0.17          0.11
## 2          0.30          0.10          0.30          0.20          0.30
## 3          0.73          0.55          0.36          0.45          0.36
## 4          0.29          0.00          0.18          0.59          0.18
## 5          0.13          0.00          0.13          0.13          0.40
## 6          0.00          0.27          0.18          1.00          0.18
##   Normalized.35 Normalized.36 Normalized.37 Normalized.38 Normalized.39
## 1          0.61          0.39          0.33          0.50          0.78
## 2          1.00          0.50          0.20          0.70          0.30
## 3          0.55          0.27          0.82          0.82          0.55
## 4          1.00          0.35          0.24          0.35          0.35
## 5          0.27          0.07          0.33          0.33          0.13
## 6          0.09          0.36          0.36          0.27          0.18
##   Normalized.40 Normalized.41 Normalized.42 Normalized.43 Normalized.44
## 1          0.22          0.44          0.06          0.22          0.28
## 2          0.20          0.50          0.20          0.40          0.50
## 3          0.00          0.18          0.27          1.00          0.18
## 4          0.59          0.24          0.41          0.47          0.06
## 5          0.13          0.33          0.27          0.53          0.27
## 6          0.45          0.36          0.36          0.18          0.36
##   Normalized.45 Normalized.46 Normalized.47 Normalized.48 Normalized.49
## 1          0.39          0.50          0.00          0.22          0.17
## 2          0.10          0.10          0.40          0.50          0.10
## 3          0.18          0.36          0.45          1.00          0.45
## 4          0.12          0.24          0.35          0.71          0.35
## 5          0.60          0.20          0.20          0.13          0.53
## 6          0.27          0.55          0.45          0.27          0.27
##   Normalized.50 Normalized.51
## 1          0.11          0.39
## 2          0.60          0.00
## 3          0.45          0.36
## 4          0.29          0.35
## 5          0.33          0.40
## 6          0.91          0.55
Data.Copy <- raw.data
#Data Manipulation
#Raw Data  Transpose
Prod_Name <- raw.data$Product_Code
rownames(raw.data) <- raw.data$Product_Code
raw.data$Product_Code <- NULL
raw.data.t<- as.data.frame(t(as.matrix(raw.data)))
head(raw.data.t)
##    P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13 P14 P15 P16 P17 P18 P19 P20
## W0 11  7  7 12  8  3  4  8 14  22  15   3  12  14  19  30  49  40  26  13
## W1 12  6 11  8  5  3  8  6  9  19   7   4  10  12  45  27  40  38  31  17
## W2 10  3  8 13 13  2  3 10 10  19  15   1   9   9  47  27  40  39  45  11
## W3  8  2  9  5 11  7  7  9  7  29  14   6   6  11  42  43  28  38  36  10
## W4 13  7 10  9  6  6  8  6 11  20  17   4  10  13  29  29  40  39  31   7
## W5 12  1  8  6  7  3  7  8 15  16   7   3  11  12  44  32  47  33  28  11
##    P21 P22 P23 P24 P25 P26 P27 P28 P29 P30 P31 P32 P33 P34 P35 P36 P37 P38
## W0  12   8   3  36  26  14  44  34  13  46   7  15  15  47  34  41  36  37
## W1   5  14   5  42  28  14  34  32  10  36  17  13  12  42  37  32  39  36
## W2   9   8   4  27  33   9  33  36  12  45   6  10  11  24  26  39  43  43
## W3   8   9   3  33  32   8  39  41  17  34   7   4  17  55  27  45  42  52
## W4   9  17   3  40  20   9  34  31  17  35   9  13  10  42  49  38  38  61
## W5   6   6   2  48  33   7  30  31  11  36   7   7  18  23  48  40  37  50
##    P39 P40 P41 P42 P43 P44 P45 P46 P47 P48 P49 P50 P51 P52 P53 P54 P55 P56
## W0  31  41  35  42  28  34  40  27  40  29  37  12  19  40   2  41  34  31
## W1  21  27  27  27  43  27  29  46  42  51  28   3  14  44   5  42  30  28
## W2  28  27  26  40  40  28  39  31  27  40  42  15  17  37   6  37  42  41
## W3  39  51  43  27  43  36  34  38  28  33  38   8  27  48   8  40  42  36
## W4  53  37  44  32  54  50  37  40  33  43  37  12  14  28   3  29  29  45
## W5  39  38  38  42  33  28  23  40  29  28  35   7  18  40   1  52  24  25
##    P57 P58 P59 P60 P61 P62 P63 P64 P65 P66 P67 P68 P69 P70 P71 P72 P73 P74
## W0  38  32   5  37  25  12  37  34  14  35  36  14  26  31   7  26  35   8
## W1  26  34  13  41  30  27  39  37  10  41  30  11  43  39  11  34  30   9
## W2  37  38  10  46  32  18  54  29   9  45  38   9  46  50  10  39  36   6
## W3  43  41  11  27  47  22  44  42  10  34  44   9  39  31   8  41  46  15
## W4  51  24  10  51  45  19  30  31  11  50  47   5  41  37  10  39  34   4
## W5  39  29  11  28  50  19  36  36   9  40  37  19  31  30  14  38  29  12
##    P75 P76 P77 P78 P79 P80 P81 P82 P83 P84 P85 P86 P87 P88 P89 P90 P91 P92
## W0  34  27   7  39  37  38  14  10  46  29  39  37  30  41  24  42  10  26
## W1  45  34   7  40  34  29   6  12  40  26  34  33  38  28  26  34  11  36
## W2  37  43   6  31  45  32  13  17  34  31  28  33  35  32  44  40   7  56
## W3  27  45   2  39  41  40   5  13  38  39  38  32  39  30  31  39  13  40
## W4  40  28   7  44  37  29   8  14  36  28  33  36  37  33  37  47   5  31
## W5  22  35   5  34  23  36  13   8  45  44  37  26  42  41  37  31   9  44
##    P93 P94 P95 P96 P97 P98 P99 P100 P101 P102 P103 P104 P105 P106 P107
## W0  11  14  12  31  29   4  16   13   26   34    7    4    2   11   19
## W1   9   9  15  35  37   2  11    6   51   41    5    4    3   10   19
## W2  10  10  15  36  36   4   9    7   45   22    7    5    3   11   15
## W3  13   9  13  44  40   4  21    9   47   32    7    5    2   16   24
## W4   5   5  17  36  33   7   9    9   40   36   14    3    5   16   16
## W5  11  11  12  38  29   2   5   15   36   27    9    7    4    7   23
##    P108 P109 P110 P111 P112 P113 P114 P115 P116 P117 P118 P119 P120 P121
## W0    0    9    9    5   31   22    7    9   13    6   16   30   37    7
## W1    2    8   12    4   36   26    6    9    7    2   13   40   35   10
## W2    2    8   12    7   32   31    7   12    8    3   10   46   27    8
## W3    0    5    6    4   51   37    8   13    8    3   10   33   30   10
## W4    3   13   15    4   39   32   10   14    7    3   16   28   31   11
## W5    1    9   10    5   33   25   12   13   12    2   15   41   42   10
##    P122 P123 P124 P125 P126 P127 P128 P129 P130 P131 P132 P133 P134 P135
## W0    7    5    4    6    3    4   36   21   19   29   39   30   32   38
## W1   10    5    6    9    8    0   43   36   53   32   36   48   41   32
## W2    7    3    0    5    8    2   28   44   43   32   45   29   50   36
## W3    8    6    7   10    3    2   39   47   41   35   41   38   35   37
## W4   11    4    4    6    5    2   41   26   39   49   43   40   36   42
## W5    2    6    3    9    3    1   37   33   46   38   37   42   35   33
##    P136 P137 P138 P139 P140 P141 P142 P143 P144 P145 P146 P147 P148 P149
## W0   39   37   36   32   28   27   23   31    9   10    7   10    3   11
## W1   37   41   44   36   36   45   29   35   13   12   13    4    2    9
## W2   39   43   22   32   41   40   40   29   17    9    9    9    8    9
## W3   52   41   35   38   46   34   43   42   12    9   13    9    3    6
## W4   38   40   34   47   34   31   34   31    8   12   10   15    5   13
## W5   28   47   34   31   38   35   30   35   21    6   12    7    7    8
##    P150 P151 P152 P153 P154 P155 P156 P157 P158 P159 P160 P161 P162 P163
## W0    4    3   11   22   12    5    1   12    8    2    9    5   13    6
## W1    3    7   10    9   14    7    4    8    3    2    8    6    9    5
## W2    3    8    8   11   11    4    6   14    3    9   10    5   12    6
## W3    4    8    8   10    6    3    6    7    2    5   13    7    9    6
## W4    6    6   13   10    8    4    3    8    3    2   14    1   11    7
## W5    2    8    4    5    7    3    8   10    3    7   10    3   11    5
##    P164 P165 P166 P167 P168 P169 P170 P171 P172 P173 P174 P175 P176 P177
## W0    9    9    7   33   34   38   29    6   32   34   37   30   38   25
## W1    5   13   10   45   29   31   37    7   48   25   42   40   44   38
## W2    8    9    9   42   34   22   32   13   44   42   30   48   41   37
## W3    9   16   11   41   59   43   43    6   40   47   43   28   26   48
## W4   14   12    5   32   27   29   30    4   31   37   48   30   28   34
## W5   10    9    8   45   39   25   27   12   40   40   44   34   36   40
##    P178 P179 P180 P181 P182 P183 P184 P185 P186 P187 P188 P189 P190 P191
## W0   35   44   40   32   42   25   30   32   36   31   33   32   54   48
## W1   34   43   38   44   28   37   37   28   34   38   34   34   41   36
## W2   40   35   34   31   34   42   38   36   37   47   36   46   51   42
## W3   36   36   43   38   28   50   30   40   36   36   52   30   45   35
## W4   45   39   43   37   26   18   32   40   41   36   42   39   51   44
## W5   37   42   34   36   35   32   32   50   33   27   49   51   46   39
##    P192 P193 P194 P195 P196 P197 P198 P199 P200 P201 P202 P203 P204 P205
## W0   24   36   35    4   43    6    7    4   18    1   10    9    1   11
## W1   33   22   37    4   34    8   19    1   14    3   10    7    2    7
## W2   30   32   31    7   39    8    4    1   21    3   10    3    1    7
## W3   35   45   23    5   32   16    9    6   17    5   11    6    1   13
## W4   36   35   37    5   45    8    8    3   26    5   11    6    1    8
## W5   43   44   42    3   35   11   12    7   14    5   11    9    3    6
##    P206 P207 P208 P209 P210 P211 P212 P213 P214 P215 P216 P217 P218 P219
## W0    1    2   30   12   16   15    0    0    0    0    0    0    0    0
## W1    0    5   26    6   12   12    0    0    0    0    0    0    0    0
## W2    1    8   36    6    9    9    0    0    0    0    0    0    0    0
## W3    3    7   33   11   14   12    0    0    0    0    0    0    0    1
## W4    1    3   33   16    7   14    0    1    0    0    0    0    0    0
## W5    3    5   30   12   11   14    1    0    1    0    0    0    0    0
##    P220 P221 P222 P223 P224 P225 P226 P227 P228 P229 P230 P231 P232 P233
## W0    0    0    0    0    0    0    0    1    0    0    0    0    0    0
## W1    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W2    0    0    0    0    0    1    0    0    0    1    1    0    0    0
## W3    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W4    0    0    0    0    1    0    0    0    0    0    0    0    0    0
## W5    0    0    0    0    1    1    0    0    0    0    0    0    0    0
##    P234 P235 P236 P237 P238 P239 P240 P241 P242 P243 P244 P245 P246 P247
## W0    0    0    0    0    0    0    0    0    0    0    0    2    0    1
## W1    0    0    0    0    0    0    0    0    0    0    0    0    0    1
## W2    0    0    0    0    0    1    1    0    0    0    0    0    0    0
## W3    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W4    1    0    0    0    0    0    0    1    0    0    0    0    0    0
## W5    0    0    0    0    0    0    0    0    1    0    0    0    0    0
##    P248 P249 P250 P251 P252 P253 P254 P255 P256 P257 P258 P259 P260 P261
## W0    0    0    0    0    0    0    0    1    0    0    0    0    0   20
## W1    0    0    0    0    0    0    0    0    0    0    0    0    0   36
## W2    0    0    0    0    0    0    0    1    0    0    0    0    0   17
## W3    0    0    0    0    0    0    0    0    0    0    0    0    1   19
## W4    0    0    0    0    0    0    0    1    0    1    0    0    0   16
## W5    0    0    0    0    0    0    1    1    0    1    0    0    0   23
##    P262 P263 P264 P265 P266 P267 P268 P269 P270 P271 P272 P273 P274 P275
## W0   25   18    8    0    6    8   18    7   26    3    0    0    0    0
## W1   31   12   16    1    8   14   18   11   16    3    0    0    0    1
## W2   33   20    9    1    7   14   18    6   23    4    0    1    0    0
## W3   23   21    9    5   15    5   14   12   19    6    3    0    0    0
## W4   38   12    9    2   17    8   18   15   29    1    0    0    0    0
## W5   34   24   10    1   10    5   24   11   21    8    1    0    0    0
##    P276 P277 P278 P279 P280 P281 P282 P283 P284 P285 P286 P287 P288 P289
## W0    0    0    0    0    0    1    0    0   26   11   17    0    1    0
## W1    0    0    0    0    1    0    0    0   17   12   19    0    1    1
## W2    0    0    0    0    0    3    0    0   17    6   13    0    0    0
## W3    0    0    0    0    0    1    0    0   22    6   15    0    0    0
## W4    0    0    0    0    0    0    3    0   23    8   16    1    1    0
## W5    0    0    0    0    0    0    1    0   24   12   23    0    0    0
##    P290 P291 P292 P293 P294 P295 P296 P297 P298 P299 P300 P301 P302 P303
## W0    0    2    2    6    9    3    7    3    5   10    6    7    4    3
## W1    0    2    7    3   13    6    5    4    7    8    7    1    2    5
## W2    1    5    5    5   19    3    6    4    4   12    3    2    5    8
## W3    0    6    4    2   13    8    4    1    1    8    1    3    2    4
## W4    1    4    4    6    5    8    6    3    4   15    8    4    4    3
## W5    0    0    3    4   10    3    3    3    3   14    9    5    7    6
##    P304 P305 P306 P307 P308 P309 P310 P311 P312 P313 P314 P315 P316 P317
## W0    7    8    4    4    7    9    5    8    3   10    6    5    4    2
## W1    6    7    2    5    3    5    4    6    2    1   17    7    5    3
## W2    6    3    3    6    2    8    4    1    3    6    9    2    9    3
## W3    8    1    8    5    4    8    2    9    8    5   14    5    2    7
## W4    9    3    7    3    6   14    5    5    3    4   10    7    1    9
## W5    9    2    4    2    3    7    1    1    6    7    8    8    8    7
##    P318 P319 P320 P321 P322 P323 P324 P325 P326 P327 P328 P329 P330 P331
## W0    3    5    2    3    4    3   11    7    3    2    4    2    4    7
## W1    5    4    5    6    5    7   11    6   11    5    6    6    4    6
## W2    5   11    8    8    2    2   15    2    7    4    6    4    8    6
## W3    9    8    7    5    2    2    6    3    6    5    6    9    2    4
## W4    9   10    2    3    7    2    6    7    4    5    4    3    4    5
## W5    1   12    6    3    3    8    9    3    7    5    9    7    5    2
##    P332 P333 P334 P335 P336 P337 P338 P339 P340 P341 P342 P343 P344 P345
## W0   10    9   11    6    2    3    2    0    0    5    3    0    1    2
## W1   14    9   13    4    3    6    2    0    0    1    2    0    2    3
## W2    8    5   15    2    5    3    1    1    0    3    2    2    0    2
## W3   12    8    8    4    3    1    3    2    0    1    2    1    3    0
## W4    6   11   16    3    1    1    4    4    0    1    3    0    0    7
## W5   10   13   16    2    4    7    2    2    0    3    0    5    0    1
##    P346 P347 P348 P349 P350 P351 P352 P354 P355 P356 P357 P358 P359 P360
## W0    0    1    1    0    0    0    0    0    0    4    3    1    3    0
## W1    0    0    0    0    0    0    0    0    0    6    1    1    5    1
## W2    0    0    0    0    0    0    0    0    0    4    3    1    3    2
## W3    0    0    0    0    0    0    0    0    0    2    4    0    5    2
## W4    0    0    0    0    0    0    0    0    0    2    2    0    4    1
## W5    0    0    1    0    0    0    0    0    0    5    3    0    5    1
##    P361 P362 P363 P364 P365 P366 P367 P368 P369 P370 P371 P372 P373 P374
## W0    6    1    2   10    6    2    0    0    3    6    2    1    0    1
## W1    3    0    1   18    5    2    2    5    2    2    4    2    3    1
## W2    3    0    0   10    5    8    2    5    2    3    3    0    0    2
## W3    2    1    0    8    1    3    1    3    3    5    1    1    0    2
## W4    3    1    0   11    5    5    1    2    3   11    2    2    1    1
## W5    0    1    0   18    2    3    5    2    7    5    2    4    1    0
##    P375 P376 P377 P378 P379 P380 P381 P382 P383 P384 P386 P387 P388 P389
## W0    1    0    1    0    0    0    0    0    0    1    0    5    5    2
## W1    0    0    0    0    1    0    0    0    0    0    0    3    2    3
## W2    1    0    0    0    0    0    0    0    0    0    0    0    1    4
## W3    0    0    0    0    0    0    0    0    0    1    0    1    1    4
## W4    0    0    0    0    0    0    1    0    0    0    0    9    1    0
## W5    0    0    0    0    0    0    0    0    0    1    0    5    2    1
##    P390 P391 P392 P393 P394 P395 P396 P397 P398 P399 P400 P401 P402 P403
## W0    4    0    3    1    1    1    0   10   14   17   20    3    1   12
## W1    4    1    3    0    4    1    1    7   12   11   11    5    0    8
## W2    3    0    7    1    2    0    1    8   10    8   19    5    6   12
## W3    2    4    5    0    9    2    4   13    8    9   16    7    0    9
## W4    3    3    5    2    1    2    3    7   14    8   22    2    3   12
## W5    1    0    4    2    2    0    1   10    8    5   20    2    4   18
##    P404 P405 P406 P407 P408 P409 P410 P411 P412 P413 P414 P415 P416 P417
## W0   11   23    6   22    7   42    6   16    4    4    2    2    1    0
## W1    8   12   12   23   10   48   13   17    2    6    2    4    1    0
## W2    7   16   17   10    8   38   16   12    4    8    1    2    1    0
## W3    9   22   15   19    9   43    9   10    8    7    1    3    0    1
## W4   11   18   14   16   13   35   18   23    5   12    5    6    0    0
## W5    6   18   18   26    8   39   16   14    3   11    2    7    0    0
##    P418 P419 P420 P421 P422 P423 P424 P425 P426 P427 P428 P429 P430 P431
## W0    0    0    0    0    1    0    0    0    0    0    0   16   13    3
## W1    0    0    0    0    1    0    0    0    0    0    0    9    8    6
## W2    0    1    0    0    0    0    1    0    1    0    0    9   14    4
## W3    0    0    0    0    1    0    0    0    0    0    0   10   12    2
## W4    1    0    0    0    0    0    1    0    0    0    0    7   15    5
## W5    0    0    1    0    0    0    0    0    0    0    0   11   12    6
##    P432 P433 P434 P435 P436 P437 P438 P439 P440 P441 P442 P443 P444 P445
## W0    6    2    2   21   14    7    1    1    1    0    0    0    0    0
## W1    7    4    0   16    5    4    1    0    0    0    0    1    0    0
## W2    6    5    7   17    6   13    0    0    0    1    1    1    0    0
## W3    5    3    1   17   12    6    0    0    0    0    0    1    0    0
## W4    6    2    3   14   10    3    2    0    0    1    0    0    0    0
## W5    5    2    2   13    6    7    0    1    0    0    0    0    0    0
##    P446 P447 P448 P449 P450 P451 P452 P453 P454 P455 P456 P457 P458 P459
## W0    0    0    0    0    1    1    0    0    0    0    0    0    0    0
## W1    1    0    2    0    0    0    0    0    0    0    0    0    0    1
## W2    1    0    0    0    0    0    0    0    0    1    0    0    0    0
## W3    0    0    2    0    0    0    0    0    0    0    2    0    0    0
## W4    0    0    1    0    1    0    1    1    0    0    0    0    0    0
## W5    0    0    0    0    3    0    0    0    0    0    0    0    0    0
##    P460 P461 P462 P463 P464 P465 P466 P467 P468 P469 P470 P471 P472 P473
## W0    1    0    0    0    0    0    0    0    0    0    0    0    0    0
## W1    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W2    0    0    0    0    0    0    0    0    0    0    0    0    1    0
## W3    0    0    0    1    0    0    0    0    0    0    0    0    0    0
## W4    1    0    0    0    0    1    0    0    0    0    0    0    0    0
## W5    0    0    1    0    0    0    0    0    0    0    0    0    1    1
##    P474 P475 P476 P477 P478 P479 P480 P481 P482 P483 P484 P485 P486 P487
## W0    0    3    1    1    1    0    0    1    0    0    3   15   16    7
## W1    0    5    0    0    0    3    0    2    0    0    5    9   30   10
## W2    0    1    1    1    0    1    0    0    1    0    3    8   25   15
## W3    0    2    1    0    2    1    0    0    0    0    6   11   11   12
## W4    0    2    3    0    3    0    0    0    1    2   10   12   23   14
## W5    0    3    0    1    0    2    0    0    0    1    5   12   19   10
##    P488 P489 P490 P491 P492 P493 P494 P495 P496 P497 P498 P499 P500 P501
## W0   10    5    6   19    9    9    6   16    5    5    4   11    8    4
## W1   11    8    7   20   14    9   13   15    3    4    4   13    8    5
## W2   10    4    6   27   14   12   12   27   13    4    6   12    3    4
## W3    9    8   12   23   13    5   15   14   11    3    8   18    4    2
## W4    9    6   13   19    5   11   16   19   10    2    8    8   13    6
## W5   14    5    9   30   16   10   19   12    9    2    1    9    9    5
##    P502 P503 P504 P505 P506 P507 P508 P509 P510 P511 P512 P513 P514 P515
## W0   11   13   10   23   23   11    9    9    9   25   17   22    7   10
## W1   15   19   13    4   16   27   10    5    4   23   17   23   14   15
## W2   19   15   11   16    9   11    9    5   10   30   16   25   13   15
## W3   15   13    5   24   11   22   12    2    6   33   16   21   11   14
## W4   14   22   13   19   16    9   11    9    5   20   27   25    9   12
## W5   11   23   12   15   19   15   17    3   11   27   18   17   19    8
##    P516 P517 P518 P519 P520 P521 P522 P523 P524 P525 P526 P527 P528 P529
## W0   24   15   15   30    9    8   12    8   14   15    9    7    9   13
## W1   18   15    6   26   12   14   15   14    9   12   13   18    9   17
## W2   15   11   14   16   11   14   16   12   10   15   15   11   10   15
## W3   21   11   12   16   16   11   10   16    7   15   18   14    5   11
## W4   20   20   11   23    8   14   19   18   11    5   15    9   13   13
## W5   19   16   18   30    9   12   11    9    8    7   10   16   22   14
##    P530 P531 P532 P533 P534 P535 P536 P537 P538 P539 P540 P541 P542 P543
## W0   20    4   15   28    6   15   14   20    7    9   23   11   12    9
## W1   11    8    5   33   10   26    9   16    7   10   19   17   14    6
## W2   22    3   10   21    9   11   13   17   13   14   21    5    7   16
## W3   14    2    8   37    7   15   13   20   14    7   23   14   13    9
## W4   15    4   12   20    7   19    3   19   11    5   20   10   11    6
## W5   20    5    8   28    9   15   21   20   11   16   21   10   13   15
##    P544 P545 P546 P547 P548 P549 P550 P551 P552 P553 P554 P555 P556 P557
## W0   15   13   10    9   32   35   11    5   15    2   24   10   15   28
## W1   10   13   14    6   28   29   10    8    9    2   15   16   11   23
## W2   14   15   13   11   39   40    6   12   10    3   32   17   26   35
## W3    7   14   11    5   36   32   11   10    8    7   28    8   15   34
## W4   12   13    9    9   47   33   11    9   11    5   22   11   13   33
## W5   13   22   13   17   40   30   19    8   15    4   21   12   11   27
##    P558 P559 P560 P561 P562 P563 P564 P565 P566 P567 P568 P569 P570 P571
## W0   15   11    9    6    6    5   13    4   24    3    4    1    2    4
## W1   10   13    9    5    5   19    4    7   26    7    2    3    2    3
## W2   15    4    3    1    0    5    8   10   22    1    1    4    0    6
## W3   13   19    7    3    4   11    9   11   24    9    5    1    2    6
## W4   16   10   11    1    4   10    6    8   20    6    2    2    0    4
## W5    8   13    8    7    4   15   10   13   13    5    2    1    2    6
##    P572 P573 P574 P575 P576 P577 P578 P579 P580 P581 P582 P583 P584 P585
## W0    2    1    0    0    0    1    1    0    1    2    3    2    2    1
## W1    0    2    1    0    0    1    0    0    5    2    4    1    3    0
## W2    0    4    0    0    0    0    1    0    4    5    2    4    2    1
## W3    0    4    0    0    1    1    0    0    7    2    3    1    6    1
## W4    1    2    0    0    0    1    0    1    2    2    5    3    2    2
## W5    3    2    0    0    0    0    0    0    5    8    1    3    2    0
##    P586 P587 P588 P589 P590 P591 P592 P593 P594 P595 P596 P597 P598 P599
## W0    7    4    5    0    3    2    2    4    1    1    2    1   10    2
## W1    2    4    2    1    4    2    0    5    2    2    3    2    6    1
## W2    4    2    1    1    4    2    0    1    3    3    5    0    6    1
## W3    6    5    0    0    6    2    1    4    5    3    4    0   15    1
## W4    8    2    1    2    4    1    0    0    3    1    3    2   10    3
## W5    8    3    2    1    4    3    0    1    4    5    3    1   14    2
##    P600 P601 P602 P603 P604 P605 P606 P607 P608 P609 P610 P611 P612 P613
## W0    0    0    0    0    0    1    1    0    1    0    6    3   14   18
## W1    1    0    0    1    0    3    1    1    1    0    3    1   11   26
## W2    3    1    0    0    0    2    0    0    0    2    1    2   13   12
## W3    1    0    1    0    0    1    1    0    0    1    4    7    9   17
## W4    1    1    1    1    0    4    1    0    0    8    5    3   13   23
## W5    1    1    0    0    0    1    1    0    0    4    1    0   14   15
##    P614 P615 P616 P617 P618 P619 P620 P621 P622 P623 P624 P625 P626 P627
## W0    4   17    6   36   40   38   31   31   29   38    5   11   10   12
## W1    4   16    6   33   35   31   27   33   33   27   10    6    6   11
## W2    2   19    3   40   49   31   37   29   39   36   13   11    8   12
## W3    3   20    2   46   31   41   29   38   40   36    6   15   13    9
## W4    4   19    6   39   34   41   34   36   40   35   12    7    9   11
## W5    6   19    2   39   45   36   39   27   37   39   10   12   16    8
##    P628 P629 P630 P631 P632 P633 P634 P635 P636 P637 P638 P639 P640 P641
## W0    7   10   11    8   13    5    6   14    6    2   15    0   14    0
## W1    6    9   11    4   11    7    8    8   15    4    7    1   20    5
## W2   13   11    8   13   14   16   13   11    9    3   10    0   15    0
## W3    9   12   12   14    9   16   10   10   14    7   18    0   11    2
## W4   11    6   26   12   11   11   11    6   18    4   21    1   10    6
## W5    5   11    5    5   14   12   12    9    7    4    8    0   20    2
##    P642 P643 P644 P646 P647 P649 P650 P651 P652 P653 P654 P655 P656 P657
## W0    5    0    0    0    0    0    0    0    0    0    0    0    0    0
## W1    3    0    0    0    0    0    0    0    0    0    0    1    0    0
## W2    4    0    0    0    0    0    0    0    0    0    0    0    0    0
## W3    2    0    0    0    0    0    0    0    0    1    0    0    0    0
## W4    2    0    0    0    0    0    0    0    0    0    0    0    0    0
## W5    2    0    0    0    0    0    0    0    0    0    0    0    0    0
##    P658 P659 P660 P661 P662 P663 P664 P665 P666 P667 P668 P669 P670 P671
## W0    0    0    0    0    0    0    0    0    1    1    1    0    0    1
## W1    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W2    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W3    0    1    1    0    0    2    0    0    0    0    0    0    0    0
## W4    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W5    0    0    0    0    0    0    0    0    0    0    0    0    0    0
##    P672 P673 P674 P675 P676 P677 P678 P679 P680 P681 P682 P683 P684 P685
## W0    0    1    4    2    1    0    0    1    0    0    0    0    0    0
## W1    0    3    4    1    1    1    0    0    0    1    0    0    0    0
## W2    0    1    8    4    3    0    0    0    0    0    0    0    0    0
## W3    0    2    7    0    2    0    0    0    0    0    0    0    0    0
## W4    0    3    2    2    5    0    0    0    0    0    0    0    0    0
## W5    0    0    6    5    4    0    0    0    0    0    0    0    0    0
##    P686 P687 P688 P689 P690 P691 P692 P693 P694 P695 P696 P697 P698 P699
## W0    2    1    0    0    0    0    0    2    0    0    0    0    2    0
## W1    4    0    0    0    0    0    2    3    0    0    0    0    2    0
## W2    0    0    0    1    0    0    3    4    0    0    0    0    2    0
## W3    1    0    0    0    0    0    0    2    0    0    0    0    1    0
## W4    2    0    1    1    2    1    2    4    0    0    0    0    0    0
## W5    4    1    0    0    0    0    3    4    0    0    1    0    2    0
##    P700 P701 P702 P703 P704 P705 P706 P707 P708 P711 P712 P713 P714 P715
## W0    1    5    3    2    0    1    0    1    0    0    0    0    0    0
## W1    0    3    1    3    0    3    0    0    1    0    0    2    0    0
## W2    0    1    4    4    2    0    0    0    0    0    0    0    0    0
## W3    5    2    4    4    1    1    0    0    0    1    0    0    0    0
## W4    0    1    4    0    0    4    0    0    0    0    0    0    1    0
## W5    1    3    6    3    0    3    1    1    0    0    0    0    1    0
##    P716 P717 P718 P719 P720 P721 P722 P724 P726 P727 P728 P729 P730 P731
## W0    1    0    0    0    0    0    0    0    0    2    1    0    0    0
## W1    0    0    2    0    0    0    0    0    1    0    0    0    1    0
## W2    0    0    0    0    0    0    0    0    0    4    1    0    0    0
## W3    0    0    0    0    0    0    0    0    2    1    1    0    0    1
## W4    1    0    0    0    0    0    0    0    2    4    0    0    0    0
## W5    0    0    1    0    0    0    0    0    2    2    1    0    0    0
##    P732 P733 P734 P735 P736 P737 P738 P739 P740 P741 P742 P743 P744 P745
## W0    0    0    1    0    1    0    0    0    0    0    0    1    0    2
## W1    1    0    0    0    1    0    0    0    0    0    0    1    0   10
## W2    1    0    0    0    0    3    0    0    0    0    1    3    0    6
## W3    1    0    1    0    0    1    0    1    0    0    0    0    1    2
## W4    1    2    0    0    0    0    0    0    1    0    1    2    0    2
## W5    1    0    0    0    2    1    0    0    0    0    1    0    0    2
##    P746 P747 P748 P749 P750 P751 P752 P753 P754 P755 P756 P757 P758 P759
## W0    1    1    0    1    0    0    4    1    0    0    0    0    0    0
## W1    0    1    1    0    0    2    0    0    0    0    0    0    0    0
## W2    0    1    1    0    0    0    2    0    0    0    1    0    0    0
## W3    0    0    0    0    0    1    3    0    0    0    0    0    0    1
## W4    1    4    0    1    0    0    2    0    0    0    0    0    0    0
## W5    2    1    3    0    1    0    2    0    0    0    0    0    0    0
##    P760 P761 P762 P763 P764 P765 P766 P767 P768 P769 P770 P771 P772 P773
## W0    0    0    2    0    1    0    0    0    0    0    2    0    0    0
## W1    0    0    3    0    2    0    1    0    0    0    0    0    0    0
## W2    0    0    2    0    5    0    1    1    2    2    0    0    0    0
## W3    0    0    1    0    3    0    0    1    8    3    0    0    0    0
## W4    0    0    0    0    0    0    0    0    2    0    0    0    1    0
## W5    0    0    2    0    3    0    1    2    5    1    1    0    1    0
##    P774 P775 P776 P777 P778 P779 P780 P781 P782 P783 P784 P785 P786 P787
## W0    0    0    0    0    0    0    0    9    5   15    3    3    1    1
## W1    0    0    0    0    0    0    0   13    7   12    1    1    2    0
## W2    0    0    0    1    0    1    0   15    4    7    2    4    2    2
## W3    0    0    0    0    0    0    0   15    6   16    1    0    2    0
## W4    0    0    0    0    0    0    0   16    2   18    3    1    1    1
## W5    0    0    0    0    0    0    0   17    2    9    4    1    0    1
##    P788 P789 P790 P791 P792 P793 P794 P795 P796 P797 P798 P799 P800 P801
## W0    4    2    3    4    0    0    0    0    2    2    6    3    3    3
## W1    3    1    1    3    1    1    0    0    5    3    0    3    2    2
## W2    3    1    5    4    0    1    1    0    0    2    3    5    1    0
## W3    5    6    2    2    1    4    0    1    3    2    1    3    0    3
## W4    1    1    0    6    0    2    0    0    3    2    0    5    0    2
## W5    4    4    4    6    3    1    0    0    0    3    2    4    0    3
##    P802 P803 P804 P805 P806 P807 P808 P809 P810 P811 P812 P813 P814 P815
## W0    1    3    2    0    4    0    0    0    0    5    3    1    4    0
## W1    1    2    2    6    5    0    3    1    0    1    2    1    2    0
## W2    1    3    5    3    7    2    3    0    1    3    0    1    2    1
## W3    0    3    3    2    4    0    3    1    0    5    0    3    6    0
## W4    3    7    1    5    7    1    1    1    0    4    2    2    0    0
## W5    2    3    4    2    2    0    2    0    0    4    1    2    4    2
##    P816 P817 P818 P819
## W0    0    1    0    0
## W1    1    0    0    1
## W2    0    0    0    0
## W3    0    0    1    0
## W4    1    1    0    0
## W5    2    1    0    0
#Slice the product weekly data based on sales

prod.wkly.sls <- raw.data.t[1:52,]
head(prod.wkly.sls)
##    P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13 P14 P15 P16 P17 P18 P19 P20
## W0 11  7  7 12  8  3  4  8 14  22  15   3  12  14  19  30  49  40  26  13
## W1 12  6 11  8  5  3  8  6  9  19   7   4  10  12  45  27  40  38  31  17
## W2 10  3  8 13 13  2  3 10 10  19  15   1   9   9  47  27  40  39  45  11
## W3  8  2  9  5 11  7  7  9  7  29  14   6   6  11  42  43  28  38  36  10
## W4 13  7 10  9  6  6  8  6 11  20  17   4  10  13  29  29  40  39  31   7
## W5 12  1  8  6  7  3  7  8 15  16   7   3  11  12  44  32  47  33  28  11
##    P21 P22 P23 P24 P25 P26 P27 P28 P29 P30 P31 P32 P33 P34 P35 P36 P37 P38
## W0  12   8   3  36  26  14  44  34  13  46   7  15  15  47  34  41  36  37
## W1   5  14   5  42  28  14  34  32  10  36  17  13  12  42  37  32  39  36
## W2   9   8   4  27  33   9  33  36  12  45   6  10  11  24  26  39  43  43
## W3   8   9   3  33  32   8  39  41  17  34   7   4  17  55  27  45  42  52
## W4   9  17   3  40  20   9  34  31  17  35   9  13  10  42  49  38  38  61
## W5   6   6   2  48  33   7  30  31  11  36   7   7  18  23  48  40  37  50
##    P39 P40 P41 P42 P43 P44 P45 P46 P47 P48 P49 P50 P51 P52 P53 P54 P55 P56
## W0  31  41  35  42  28  34  40  27  40  29  37  12  19  40   2  41  34  31
## W1  21  27  27  27  43  27  29  46  42  51  28   3  14  44   5  42  30  28
## W2  28  27  26  40  40  28  39  31  27  40  42  15  17  37   6  37  42  41
## W3  39  51  43  27  43  36  34  38  28  33  38   8  27  48   8  40  42  36
## W4  53  37  44  32  54  50  37  40  33  43  37  12  14  28   3  29  29  45
## W5  39  38  38  42  33  28  23  40  29  28  35   7  18  40   1  52  24  25
##    P57 P58 P59 P60 P61 P62 P63 P64 P65 P66 P67 P68 P69 P70 P71 P72 P73 P74
## W0  38  32   5  37  25  12  37  34  14  35  36  14  26  31   7  26  35   8
## W1  26  34  13  41  30  27  39  37  10  41  30  11  43  39  11  34  30   9
## W2  37  38  10  46  32  18  54  29   9  45  38   9  46  50  10  39  36   6
## W3  43  41  11  27  47  22  44  42  10  34  44   9  39  31   8  41  46  15
## W4  51  24  10  51  45  19  30  31  11  50  47   5  41  37  10  39  34   4
## W5  39  29  11  28  50  19  36  36   9  40  37  19  31  30  14  38  29  12
##    P75 P76 P77 P78 P79 P80 P81 P82 P83 P84 P85 P86 P87 P88 P89 P90 P91 P92
## W0  34  27   7  39  37  38  14  10  46  29  39  37  30  41  24  42  10  26
## W1  45  34   7  40  34  29   6  12  40  26  34  33  38  28  26  34  11  36
## W2  37  43   6  31  45  32  13  17  34  31  28  33  35  32  44  40   7  56
## W3  27  45   2  39  41  40   5  13  38  39  38  32  39  30  31  39  13  40
## W4  40  28   7  44  37  29   8  14  36  28  33  36  37  33  37  47   5  31
## W5  22  35   5  34  23  36  13   8  45  44  37  26  42  41  37  31   9  44
##    P93 P94 P95 P96 P97 P98 P99 P100 P101 P102 P103 P104 P105 P106 P107
## W0  11  14  12  31  29   4  16   13   26   34    7    4    2   11   19
## W1   9   9  15  35  37   2  11    6   51   41    5    4    3   10   19
## W2  10  10  15  36  36   4   9    7   45   22    7    5    3   11   15
## W3  13   9  13  44  40   4  21    9   47   32    7    5    2   16   24
## W4   5   5  17  36  33   7   9    9   40   36   14    3    5   16   16
## W5  11  11  12  38  29   2   5   15   36   27    9    7    4    7   23
##    P108 P109 P110 P111 P112 P113 P114 P115 P116 P117 P118 P119 P120 P121
## W0    0    9    9    5   31   22    7    9   13    6   16   30   37    7
## W1    2    8   12    4   36   26    6    9    7    2   13   40   35   10
## W2    2    8   12    7   32   31    7   12    8    3   10   46   27    8
## W3    0    5    6    4   51   37    8   13    8    3   10   33   30   10
## W4    3   13   15    4   39   32   10   14    7    3   16   28   31   11
## W5    1    9   10    5   33   25   12   13   12    2   15   41   42   10
##    P122 P123 P124 P125 P126 P127 P128 P129 P130 P131 P132 P133 P134 P135
## W0    7    5    4    6    3    4   36   21   19   29   39   30   32   38
## W1   10    5    6    9    8    0   43   36   53   32   36   48   41   32
## W2    7    3    0    5    8    2   28   44   43   32   45   29   50   36
## W3    8    6    7   10    3    2   39   47   41   35   41   38   35   37
## W4   11    4    4    6    5    2   41   26   39   49   43   40   36   42
## W5    2    6    3    9    3    1   37   33   46   38   37   42   35   33
##    P136 P137 P138 P139 P140 P141 P142 P143 P144 P145 P146 P147 P148 P149
## W0   39   37   36   32   28   27   23   31    9   10    7   10    3   11
## W1   37   41   44   36   36   45   29   35   13   12   13    4    2    9
## W2   39   43   22   32   41   40   40   29   17    9    9    9    8    9
## W3   52   41   35   38   46   34   43   42   12    9   13    9    3    6
## W4   38   40   34   47   34   31   34   31    8   12   10   15    5   13
## W5   28   47   34   31   38   35   30   35   21    6   12    7    7    8
##    P150 P151 P152 P153 P154 P155 P156 P157 P158 P159 P160 P161 P162 P163
## W0    4    3   11   22   12    5    1   12    8    2    9    5   13    6
## W1    3    7   10    9   14    7    4    8    3    2    8    6    9    5
## W2    3    8    8   11   11    4    6   14    3    9   10    5   12    6
## W3    4    8    8   10    6    3    6    7    2    5   13    7    9    6
## W4    6    6   13   10    8    4    3    8    3    2   14    1   11    7
## W5    2    8    4    5    7    3    8   10    3    7   10    3   11    5
##    P164 P165 P166 P167 P168 P169 P170 P171 P172 P173 P174 P175 P176 P177
## W0    9    9    7   33   34   38   29    6   32   34   37   30   38   25
## W1    5   13   10   45   29   31   37    7   48   25   42   40   44   38
## W2    8    9    9   42   34   22   32   13   44   42   30   48   41   37
## W3    9   16   11   41   59   43   43    6   40   47   43   28   26   48
## W4   14   12    5   32   27   29   30    4   31   37   48   30   28   34
## W5   10    9    8   45   39   25   27   12   40   40   44   34   36   40
##    P178 P179 P180 P181 P182 P183 P184 P185 P186 P187 P188 P189 P190 P191
## W0   35   44   40   32   42   25   30   32   36   31   33   32   54   48
## W1   34   43   38   44   28   37   37   28   34   38   34   34   41   36
## W2   40   35   34   31   34   42   38   36   37   47   36   46   51   42
## W3   36   36   43   38   28   50   30   40   36   36   52   30   45   35
## W4   45   39   43   37   26   18   32   40   41   36   42   39   51   44
## W5   37   42   34   36   35   32   32   50   33   27   49   51   46   39
##    P192 P193 P194 P195 P196 P197 P198 P199 P200 P201 P202 P203 P204 P205
## W0   24   36   35    4   43    6    7    4   18    1   10    9    1   11
## W1   33   22   37    4   34    8   19    1   14    3   10    7    2    7
## W2   30   32   31    7   39    8    4    1   21    3   10    3    1    7
## W3   35   45   23    5   32   16    9    6   17    5   11    6    1   13
## W4   36   35   37    5   45    8    8    3   26    5   11    6    1    8
## W5   43   44   42    3   35   11   12    7   14    5   11    9    3    6
##    P206 P207 P208 P209 P210 P211 P212 P213 P214 P215 P216 P217 P218 P219
## W0    1    2   30   12   16   15    0    0    0    0    0    0    0    0
## W1    0    5   26    6   12   12    0    0    0    0    0    0    0    0
## W2    1    8   36    6    9    9    0    0    0    0    0    0    0    0
## W3    3    7   33   11   14   12    0    0    0    0    0    0    0    1
## W4    1    3   33   16    7   14    0    1    0    0    0    0    0    0
## W5    3    5   30   12   11   14    1    0    1    0    0    0    0    0
##    P220 P221 P222 P223 P224 P225 P226 P227 P228 P229 P230 P231 P232 P233
## W0    0    0    0    0    0    0    0    1    0    0    0    0    0    0
## W1    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W2    0    0    0    0    0    1    0    0    0    1    1    0    0    0
## W3    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W4    0    0    0    0    1    0    0    0    0    0    0    0    0    0
## W5    0    0    0    0    1    1    0    0    0    0    0    0    0    0
##    P234 P235 P236 P237 P238 P239 P240 P241 P242 P243 P244 P245 P246 P247
## W0    0    0    0    0    0    0    0    0    0    0    0    2    0    1
## W1    0    0    0    0    0    0    0    0    0    0    0    0    0    1
## W2    0    0    0    0    0    1    1    0    0    0    0    0    0    0
## W3    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W4    1    0    0    0    0    0    0    1    0    0    0    0    0    0
## W5    0    0    0    0    0    0    0    0    1    0    0    0    0    0
##    P248 P249 P250 P251 P252 P253 P254 P255 P256 P257 P258 P259 P260 P261
## W0    0    0    0    0    0    0    0    1    0    0    0    0    0   20
## W1    0    0    0    0    0    0    0    0    0    0    0    0    0   36
## W2    0    0    0    0    0    0    0    1    0    0    0    0    0   17
## W3    0    0    0    0    0    0    0    0    0    0    0    0    1   19
## W4    0    0    0    0    0    0    0    1    0    1    0    0    0   16
## W5    0    0    0    0    0    0    1    1    0    1    0    0    0   23
##    P262 P263 P264 P265 P266 P267 P268 P269 P270 P271 P272 P273 P274 P275
## W0   25   18    8    0    6    8   18    7   26    3    0    0    0    0
## W1   31   12   16    1    8   14   18   11   16    3    0    0    0    1
## W2   33   20    9    1    7   14   18    6   23    4    0    1    0    0
## W3   23   21    9    5   15    5   14   12   19    6    3    0    0    0
## W4   38   12    9    2   17    8   18   15   29    1    0    0    0    0
## W5   34   24   10    1   10    5   24   11   21    8    1    0    0    0
##    P276 P277 P278 P279 P280 P281 P282 P283 P284 P285 P286 P287 P288 P289
## W0    0    0    0    0    0    1    0    0   26   11   17    0    1    0
## W1    0    0    0    0    1    0    0    0   17   12   19    0    1    1
## W2    0    0    0    0    0    3    0    0   17    6   13    0    0    0
## W3    0    0    0    0    0    1    0    0   22    6   15    0    0    0
## W4    0    0    0    0    0    0    3    0   23    8   16    1    1    0
## W5    0    0    0    0    0    0    1    0   24   12   23    0    0    0
##    P290 P291 P292 P293 P294 P295 P296 P297 P298 P299 P300 P301 P302 P303
## W0    0    2    2    6    9    3    7    3    5   10    6    7    4    3
## W1    0    2    7    3   13    6    5    4    7    8    7    1    2    5
## W2    1    5    5    5   19    3    6    4    4   12    3    2    5    8
## W3    0    6    4    2   13    8    4    1    1    8    1    3    2    4
## W4    1    4    4    6    5    8    6    3    4   15    8    4    4    3
## W5    0    0    3    4   10    3    3    3    3   14    9    5    7    6
##    P304 P305 P306 P307 P308 P309 P310 P311 P312 P313 P314 P315 P316 P317
## W0    7    8    4    4    7    9    5    8    3   10    6    5    4    2
## W1    6    7    2    5    3    5    4    6    2    1   17    7    5    3
## W2    6    3    3    6    2    8    4    1    3    6    9    2    9    3
## W3    8    1    8    5    4    8    2    9    8    5   14    5    2    7
## W4    9    3    7    3    6   14    5    5    3    4   10    7    1    9
## W5    9    2    4    2    3    7    1    1    6    7    8    8    8    7
##    P318 P319 P320 P321 P322 P323 P324 P325 P326 P327 P328 P329 P330 P331
## W0    3    5    2    3    4    3   11    7    3    2    4    2    4    7
## W1    5    4    5    6    5    7   11    6   11    5    6    6    4    6
## W2    5   11    8    8    2    2   15    2    7    4    6    4    8    6
## W3    9    8    7    5    2    2    6    3    6    5    6    9    2    4
## W4    9   10    2    3    7    2    6    7    4    5    4    3    4    5
## W5    1   12    6    3    3    8    9    3    7    5    9    7    5    2
##    P332 P333 P334 P335 P336 P337 P338 P339 P340 P341 P342 P343 P344 P345
## W0   10    9   11    6    2    3    2    0    0    5    3    0    1    2
## W1   14    9   13    4    3    6    2    0    0    1    2    0    2    3
## W2    8    5   15    2    5    3    1    1    0    3    2    2    0    2
## W3   12    8    8    4    3    1    3    2    0    1    2    1    3    0
## W4    6   11   16    3    1    1    4    4    0    1    3    0    0    7
## W5   10   13   16    2    4    7    2    2    0    3    0    5    0    1
##    P346 P347 P348 P349 P350 P351 P352 P354 P355 P356 P357 P358 P359 P360
## W0    0    1    1    0    0    0    0    0    0    4    3    1    3    0
## W1    0    0    0    0    0    0    0    0    0    6    1    1    5    1
## W2    0    0    0    0    0    0    0    0    0    4    3    1    3    2
## W3    0    0    0    0    0    0    0    0    0    2    4    0    5    2
## W4    0    0    0    0    0    0    0    0    0    2    2    0    4    1
## W5    0    0    1    0    0    0    0    0    0    5    3    0    5    1
##    P361 P362 P363 P364 P365 P366 P367 P368 P369 P370 P371 P372 P373 P374
## W0    6    1    2   10    6    2    0    0    3    6    2    1    0    1
## W1    3    0    1   18    5    2    2    5    2    2    4    2    3    1
## W2    3    0    0   10    5    8    2    5    2    3    3    0    0    2
## W3    2    1    0    8    1    3    1    3    3    5    1    1    0    2
## W4    3    1    0   11    5    5    1    2    3   11    2    2    1    1
## W5    0    1    0   18    2    3    5    2    7    5    2    4    1    0
##    P375 P376 P377 P378 P379 P380 P381 P382 P383 P384 P386 P387 P388 P389
## W0    1    0    1    0    0    0    0    0    0    1    0    5    5    2
## W1    0    0    0    0    1    0    0    0    0    0    0    3    2    3
## W2    1    0    0    0    0    0    0    0    0    0    0    0    1    4
## W3    0    0    0    0    0    0    0    0    0    1    0    1    1    4
## W4    0    0    0    0    0    0    1    0    0    0    0    9    1    0
## W5    0    0    0    0    0    0    0    0    0    1    0    5    2    1
##    P390 P391 P392 P393 P394 P395 P396 P397 P398 P399 P400 P401 P402 P403
## W0    4    0    3    1    1    1    0   10   14   17   20    3    1   12
## W1    4    1    3    0    4    1    1    7   12   11   11    5    0    8
## W2    3    0    7    1    2    0    1    8   10    8   19    5    6   12
## W3    2    4    5    0    9    2    4   13    8    9   16    7    0    9
## W4    3    3    5    2    1    2    3    7   14    8   22    2    3   12
## W5    1    0    4    2    2    0    1   10    8    5   20    2    4   18
##    P404 P405 P406 P407 P408 P409 P410 P411 P412 P413 P414 P415 P416 P417
## W0   11   23    6   22    7   42    6   16    4    4    2    2    1    0
## W1    8   12   12   23   10   48   13   17    2    6    2    4    1    0
## W2    7   16   17   10    8   38   16   12    4    8    1    2    1    0
## W3    9   22   15   19    9   43    9   10    8    7    1    3    0    1
## W4   11   18   14   16   13   35   18   23    5   12    5    6    0    0
## W5    6   18   18   26    8   39   16   14    3   11    2    7    0    0
##    P418 P419 P420 P421 P422 P423 P424 P425 P426 P427 P428 P429 P430 P431
## W0    0    0    0    0    1    0    0    0    0    0    0   16   13    3
## W1    0    0    0    0    1    0    0    0    0    0    0    9    8    6
## W2    0    1    0    0    0    0    1    0    1    0    0    9   14    4
## W3    0    0    0    0    1    0    0    0    0    0    0   10   12    2
## W4    1    0    0    0    0    0    1    0    0    0    0    7   15    5
## W5    0    0    1    0    0    0    0    0    0    0    0   11   12    6
##    P432 P433 P434 P435 P436 P437 P438 P439 P440 P441 P442 P443 P444 P445
## W0    6    2    2   21   14    7    1    1    1    0    0    0    0    0
## W1    7    4    0   16    5    4    1    0    0    0    0    1    0    0
## W2    6    5    7   17    6   13    0    0    0    1    1    1    0    0
## W3    5    3    1   17   12    6    0    0    0    0    0    1    0    0
## W4    6    2    3   14   10    3    2    0    0    1    0    0    0    0
## W5    5    2    2   13    6    7    0    1    0    0    0    0    0    0
##    P446 P447 P448 P449 P450 P451 P452 P453 P454 P455 P456 P457 P458 P459
## W0    0    0    0    0    1    1    0    0    0    0    0    0    0    0
## W1    1    0    2    0    0    0    0    0    0    0    0    0    0    1
## W2    1    0    0    0    0    0    0    0    0    1    0    0    0    0
## W3    0    0    2    0    0    0    0    0    0    0    2    0    0    0
## W4    0    0    1    0    1    0    1    1    0    0    0    0    0    0
## W5    0    0    0    0    3    0    0    0    0    0    0    0    0    0
##    P460 P461 P462 P463 P464 P465 P466 P467 P468 P469 P470 P471 P472 P473
## W0    1    0    0    0    0    0    0    0    0    0    0    0    0    0
## W1    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W2    0    0    0    0    0    0    0    0    0    0    0    0    1    0
## W3    0    0    0    1    0    0    0    0    0    0    0    0    0    0
## W4    1    0    0    0    0    1    0    0    0    0    0    0    0    0
## W5    0    0    1    0    0    0    0    0    0    0    0    0    1    1
##    P474 P475 P476 P477 P478 P479 P480 P481 P482 P483 P484 P485 P486 P487
## W0    0    3    1    1    1    0    0    1    0    0    3   15   16    7
## W1    0    5    0    0    0    3    0    2    0    0    5    9   30   10
## W2    0    1    1    1    0    1    0    0    1    0    3    8   25   15
## W3    0    2    1    0    2    1    0    0    0    0    6   11   11   12
## W4    0    2    3    0    3    0    0    0    1    2   10   12   23   14
## W5    0    3    0    1    0    2    0    0    0    1    5   12   19   10
##    P488 P489 P490 P491 P492 P493 P494 P495 P496 P497 P498 P499 P500 P501
## W0   10    5    6   19    9    9    6   16    5    5    4   11    8    4
## W1   11    8    7   20   14    9   13   15    3    4    4   13    8    5
## W2   10    4    6   27   14   12   12   27   13    4    6   12    3    4
## W3    9    8   12   23   13    5   15   14   11    3    8   18    4    2
## W4    9    6   13   19    5   11   16   19   10    2    8    8   13    6
## W5   14    5    9   30   16   10   19   12    9    2    1    9    9    5
##    P502 P503 P504 P505 P506 P507 P508 P509 P510 P511 P512 P513 P514 P515
## W0   11   13   10   23   23   11    9    9    9   25   17   22    7   10
## W1   15   19   13    4   16   27   10    5    4   23   17   23   14   15
## W2   19   15   11   16    9   11    9    5   10   30   16   25   13   15
## W3   15   13    5   24   11   22   12    2    6   33   16   21   11   14
## W4   14   22   13   19   16    9   11    9    5   20   27   25    9   12
## W5   11   23   12   15   19   15   17    3   11   27   18   17   19    8
##    P516 P517 P518 P519 P520 P521 P522 P523 P524 P525 P526 P527 P528 P529
## W0   24   15   15   30    9    8   12    8   14   15    9    7    9   13
## W1   18   15    6   26   12   14   15   14    9   12   13   18    9   17
## W2   15   11   14   16   11   14   16   12   10   15   15   11   10   15
## W3   21   11   12   16   16   11   10   16    7   15   18   14    5   11
## W4   20   20   11   23    8   14   19   18   11    5   15    9   13   13
## W5   19   16   18   30    9   12   11    9    8    7   10   16   22   14
##    P530 P531 P532 P533 P534 P535 P536 P537 P538 P539 P540 P541 P542 P543
## W0   20    4   15   28    6   15   14   20    7    9   23   11   12    9
## W1   11    8    5   33   10   26    9   16    7   10   19   17   14    6
## W2   22    3   10   21    9   11   13   17   13   14   21    5    7   16
## W3   14    2    8   37    7   15   13   20   14    7   23   14   13    9
## W4   15    4   12   20    7   19    3   19   11    5   20   10   11    6
## W5   20    5    8   28    9   15   21   20   11   16   21   10   13   15
##    P544 P545 P546 P547 P548 P549 P550 P551 P552 P553 P554 P555 P556 P557
## W0   15   13   10    9   32   35   11    5   15    2   24   10   15   28
## W1   10   13   14    6   28   29   10    8    9    2   15   16   11   23
## W2   14   15   13   11   39   40    6   12   10    3   32   17   26   35
## W3    7   14   11    5   36   32   11   10    8    7   28    8   15   34
## W4   12   13    9    9   47   33   11    9   11    5   22   11   13   33
## W5   13   22   13   17   40   30   19    8   15    4   21   12   11   27
##    P558 P559 P560 P561 P562 P563 P564 P565 P566 P567 P568 P569 P570 P571
## W0   15   11    9    6    6    5   13    4   24    3    4    1    2    4
## W1   10   13    9    5    5   19    4    7   26    7    2    3    2    3
## W2   15    4    3    1    0    5    8   10   22    1    1    4    0    6
## W3   13   19    7    3    4   11    9   11   24    9    5    1    2    6
## W4   16   10   11    1    4   10    6    8   20    6    2    2    0    4
## W5    8   13    8    7    4   15   10   13   13    5    2    1    2    6
##    P572 P573 P574 P575 P576 P577 P578 P579 P580 P581 P582 P583 P584 P585
## W0    2    1    0    0    0    1    1    0    1    2    3    2    2    1
## W1    0    2    1    0    0    1    0    0    5    2    4    1    3    0
## W2    0    4    0    0    0    0    1    0    4    5    2    4    2    1
## W3    0    4    0    0    1    1    0    0    7    2    3    1    6    1
## W4    1    2    0    0    0    1    0    1    2    2    5    3    2    2
## W5    3    2    0    0    0    0    0    0    5    8    1    3    2    0
##    P586 P587 P588 P589 P590 P591 P592 P593 P594 P595 P596 P597 P598 P599
## W0    7    4    5    0    3    2    2    4    1    1    2    1   10    2
## W1    2    4    2    1    4    2    0    5    2    2    3    2    6    1
## W2    4    2    1    1    4    2    0    1    3    3    5    0    6    1
## W3    6    5    0    0    6    2    1    4    5    3    4    0   15    1
## W4    8    2    1    2    4    1    0    0    3    1    3    2   10    3
## W5    8    3    2    1    4    3    0    1    4    5    3    1   14    2
##    P600 P601 P602 P603 P604 P605 P606 P607 P608 P609 P610 P611 P612 P613
## W0    0    0    0    0    0    1    1    0    1    0    6    3   14   18
## W1    1    0    0    1    0    3    1    1    1    0    3    1   11   26
## W2    3    1    0    0    0    2    0    0    0    2    1    2   13   12
## W3    1    0    1    0    0    1    1    0    0    1    4    7    9   17
## W4    1    1    1    1    0    4    1    0    0    8    5    3   13   23
## W5    1    1    0    0    0    1    1    0    0    4    1    0   14   15
##    P614 P615 P616 P617 P618 P619 P620 P621 P622 P623 P624 P625 P626 P627
## W0    4   17    6   36   40   38   31   31   29   38    5   11   10   12
## W1    4   16    6   33   35   31   27   33   33   27   10    6    6   11
## W2    2   19    3   40   49   31   37   29   39   36   13   11    8   12
## W3    3   20    2   46   31   41   29   38   40   36    6   15   13    9
## W4    4   19    6   39   34   41   34   36   40   35   12    7    9   11
## W5    6   19    2   39   45   36   39   27   37   39   10   12   16    8
##    P628 P629 P630 P631 P632 P633 P634 P635 P636 P637 P638 P639 P640 P641
## W0    7   10   11    8   13    5    6   14    6    2   15    0   14    0
## W1    6    9   11    4   11    7    8    8   15    4    7    1   20    5
## W2   13   11    8   13   14   16   13   11    9    3   10    0   15    0
## W3    9   12   12   14    9   16   10   10   14    7   18    0   11    2
## W4   11    6   26   12   11   11   11    6   18    4   21    1   10    6
## W5    5   11    5    5   14   12   12    9    7    4    8    0   20    2
##    P642 P643 P644 P646 P647 P649 P650 P651 P652 P653 P654 P655 P656 P657
## W0    5    0    0    0    0    0    0    0    0    0    0    0    0    0
## W1    3    0    0    0    0    0    0    0    0    0    0    1    0    0
## W2    4    0    0    0    0    0    0    0    0    0    0    0    0    0
## W3    2    0    0    0    0    0    0    0    0    1    0    0    0    0
## W4    2    0    0    0    0    0    0    0    0    0    0    0    0    0
## W5    2    0    0    0    0    0    0    0    0    0    0    0    0    0
##    P658 P659 P660 P661 P662 P663 P664 P665 P666 P667 P668 P669 P670 P671
## W0    0    0    0    0    0    0    0    0    1    1    1    0    0    1
## W1    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W2    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W3    0    1    1    0    0    2    0    0    0    0    0    0    0    0
## W4    0    0    0    0    0    0    0    0    0    0    0    0    0    0
## W5    0    0    0    0    0    0    0    0    0    0    0    0    0    0
##    P672 P673 P674 P675 P676 P677 P678 P679 P680 P681 P682 P683 P684 P685
## W0    0    1    4    2    1    0    0    1    0    0    0    0    0    0
## W1    0    3    4    1    1    1    0    0    0    1    0    0    0    0
## W2    0    1    8    4    3    0    0    0    0    0    0    0    0    0
## W3    0    2    7    0    2    0    0    0    0    0    0    0    0    0
## W4    0    3    2    2    5    0    0    0    0    0    0    0    0    0
## W5    0    0    6    5    4    0    0    0    0    0    0    0    0    0
##    P686 P687 P688 P689 P690 P691 P692 P693 P694 P695 P696 P697 P698 P699
## W0    2    1    0    0    0    0    0    2    0    0    0    0    2    0
## W1    4    0    0    0    0    0    2    3    0    0    0    0    2    0
## W2    0    0    0    1    0    0    3    4    0    0    0    0    2    0
## W3    1    0    0    0    0    0    0    2    0    0    0    0    1    0
## W4    2    0    1    1    2    1    2    4    0    0    0    0    0    0
## W5    4    1    0    0    0    0    3    4    0    0    1    0    2    0
##    P700 P701 P702 P703 P704 P705 P706 P707 P708 P711 P712 P713 P714 P715
## W0    1    5    3    2    0    1    0    1    0    0    0    0    0    0
## W1    0    3    1    3    0    3    0    0    1    0    0    2    0    0
## W2    0    1    4    4    2    0    0    0    0    0    0    0    0    0
## W3    5    2    4    4    1    1    0    0    0    1    0    0    0    0
## W4    0    1    4    0    0    4    0    0    0    0    0    0    1    0
## W5    1    3    6    3    0    3    1    1    0    0    0    0    1    0
##    P716 P717 P718 P719 P720 P721 P722 P724 P726 P727 P728 P729 P730 P731
## W0    1    0    0    0    0    0    0    0    0    2    1    0    0    0
## W1    0    0    2    0    0    0    0    0    1    0    0    0    1    0
## W2    0    0    0    0    0    0    0    0    0    4    1    0    0    0
## W3    0    0    0    0    0    0    0    0    2    1    1    0    0    1
## W4    1    0    0    0    0    0    0    0    2    4    0    0    0    0
## W5    0    0    1    0    0    0    0    0    2    2    1    0    0    0
##    P732 P733 P734 P735 P736 P737 P738 P739 P740 P741 P742 P743 P744 P745
## W0    0    0    1    0    1    0    0    0    0    0    0    1    0    2
## W1    1    0    0    0    1    0    0    0    0    0    0    1    0   10
## W2    1    0    0    0    0    3    0    0    0    0    1    3    0    6
## W3    1    0    1    0    0    1    0    1    0    0    0    0    1    2
## W4    1    2    0    0    0    0    0    0    1    0    1    2    0    2
## W5    1    0    0    0    2    1    0    0    0    0    1    0    0    2
##    P746 P747 P748 P749 P750 P751 P752 P753 P754 P755 P756 P757 P758 P759
## W0    1    1    0    1    0    0    4    1    0    0    0    0    0    0
## W1    0    1    1    0    0    2    0    0    0    0    0    0    0    0
## W2    0    1    1    0    0    0    2    0    0    0    1    0    0    0
## W3    0    0    0    0    0    1    3    0    0    0    0    0    0    1
## W4    1    4    0    1    0    0    2    0    0    0    0    0    0    0
## W5    2    1    3    0    1    0    2    0    0    0    0    0    0    0
##    P760 P761 P762 P763 P764 P765 P766 P767 P768 P769 P770 P771 P772 P773
## W0    0    0    2    0    1    0    0    0    0    0    2    0    0    0
## W1    0    0    3    0    2    0    1    0    0    0    0    0    0    0
## W2    0    0    2    0    5    0    1    1    2    2    0    0    0    0
## W3    0    0    1    0    3    0    0    1    8    3    0    0    0    0
## W4    0    0    0    0    0    0    0    0    2    0    0    0    1    0
## W5    0    0    2    0    3    0    1    2    5    1    1    0    1    0
##    P774 P775 P776 P777 P778 P779 P780 P781 P782 P783 P784 P785 P786 P787
## W0    0    0    0    0    0    0    0    9    5   15    3    3    1    1
## W1    0    0    0    0    0    0    0   13    7   12    1    1    2    0
## W2    0    0    0    1    0    1    0   15    4    7    2    4    2    2
## W3    0    0    0    0    0    0    0   15    6   16    1    0    2    0
## W4    0    0    0    0    0    0    0   16    2   18    3    1    1    1
## W5    0    0    0    0    0    0    0   17    2    9    4    1    0    1
##    P788 P789 P790 P791 P792 P793 P794 P795 P796 P797 P798 P799 P800 P801
## W0    4    2    3    4    0    0    0    0    2    2    6    3    3    3
## W1    3    1    1    3    1    1    0    0    5    3    0    3    2    2
## W2    3    1    5    4    0    1    1    0    0    2    3    5    1    0
## W3    5    6    2    2    1    4    0    1    3    2    1    3    0    3
## W4    1    1    0    6    0    2    0    0    3    2    0    5    0    2
## W5    4    4    4    6    3    1    0    0    0    3    2    4    0    3
##    P802 P803 P804 P805 P806 P807 P808 P809 P810 P811 P812 P813 P814 P815
## W0    1    3    2    0    4    0    0    0    0    5    3    1    4    0
## W1    1    2    2    6    5    0    3    1    0    1    2    1    2    0
## W2    1    3    5    3    7    2    3    0    1    3    0    1    2    1
## W3    0    3    3    2    4    0    3    1    0    5    0    3    6    0
## W4    3    7    1    5    7    1    1    1    0    4    2    2    0    0
## W5    2    3    4    2    2    0    2    0    0    4    1    2    4    2
##    P816 P817 P818 P819
## W0    0    1    0    0
## W1    1    0    0    1
## W2    0    0    0    0
## W3    0    0    1    0
## W4    1    1    0    0
## W5    2    1    0    0
#Identify the total sales in an year of all the product
#Store the product names
Prdt<- colnames(prod.wkly.sls)
#Created a dataframe with total sales at product level
Tot.Sls.By.Prdt <- as.data.frame(colSums(prod.wkly.sls[,c(1:811)])) 
names(Tot.Sls.By.Prdt)[1] <- "Yr.Sls"
Tot.Sls.By.Prdt <- cbind(Prdt,Tot.Sls.By.Prdt)
rownames(Tot.Sls.By.Prdt) <- NULL
summary(Tot.Sls.By.Prdt)
##       Prdt         Yr.Sls      
##  P1     :  1   Min.   :   1.0  
##  P10    :  1   1st Qu.:  21.0  
##  P100   :  1   Median : 199.0  
##  P101   :  1   Mean   : 462.7  
##  P102   :  1   3rd Qu.: 575.0  
##  P103   :  1   Max.   :2220.0  
##  (Other):805
Tot.Sls.By.Prdt$Yr.Sls <- as.numeric(Tot.Sls.By.Prdt$Yr.Sls )
#Top5 Product by Yearly Sale
Top5.Prdt.Sls <- Tot.Sls.By.Prdt %>% 
    select(Prdt,Yr.Sls) %>% arrange(desc(Yr.Sls)) %>% top_n(5,Yr.Sls)
## Warning: package 'bindrcpp' was built under R version 3.5.1
# Plot top 5 Product by Sale
ggplot(Top5.Prdt.Sls, aes(x=reorder(Prdt,-Yr.Sls), y= Yr.Sls)) + 
  geom_bar(stat="identity", width=.5, fill="tomato3") + 
  labs(title="Top 5 Products by Yearly Sale", 
       subtitle="Yearly", 
       caption="Product:Sales",
       y="Total Sales",
       x="Product") + 
  theme(axis.text.x = element_text(angle=65, vjust=0.6))

#Quarterly sales of top 5 Product analysis
Top5.Prdt.Sls$Prdt
## [1] P409 P34  P178 P135 P43 
## 811 Levels: P1 P10 P100 P101 P102 P103 P104 P105 P106 P107 P108 ... P99
Q1.Sls.By.Prdt <- as.data.frame(colSums(prod.wkly.sls[1:13,c(1:811)])) 
names(Q1.Sls.By.Prdt)[1] <- "Q1.Sls"
Q2.Sls.By.Prdt <- as.data.frame(colSums(prod.wkly.sls[14:26,c(1:811)])) 
names(Q2.Sls.By.Prdt)[1] <- "Q2.Sls"
Q3.Sls.By.Prdt <- as.data.frame(colSums(prod.wkly.sls[27:39,c(1:811)])) 
names(Q3.Sls.By.Prdt)[1] <- "Q3.Sls"
Q4.Sls.By.Prdt <- as.data.frame(colSums(prod.wkly.sls[40:52,c(1:811)])) 
names(Q4.Sls.By.Prdt)[1] <- "Q4.Sls"

Qtr.Sls.By.Prdt<-as.data.frame(cbind(Prdt,"Q1.Sls"=Q1.Sls.By.Prdt$Q1.Sls,"Q2.Sls"=Q2.Sls.By.Prdt$Q2.Sls,"Q3.Sls"=Q3.Sls.By.Prdt$Q3.Sls,"Q4.Sls"=Q4.Sls.By.Prdt$Q4.Sls))
Qtr.Sls.By.Prdt
##     Prdt Q1.Sls Q2.Sls Q3.Sls Q4.Sls
## 1     P1    162    114    118    107
## 2     P2     51     58     59     39
## 3     P3    118    119    116     99
## 4     P4    116    111    100    103
## 5     P5    128    125     87    100
## 6     P6     54     69     40     57
## 7     P7     65     62     39     47
## 8     P8    110    126    115     99
## 9     P9    156    162    108    113
## 10   P10    291    281    216    222
## 11   P11    148    154    133    166
## 12   P12     55     51     52     45
## 13   P13    145    116    104    105
## 14   P14    155    212    112    136
## 15   P15    506    487    405    407
## 16   P16    480    511    446    438
## 17   P17    514    483    350    418
## 18   P18    470    465    371    376
## 19   P19    449    454    406    378
## 20   P20    141    119     92    113
## 21   P21    128    125     96    113
## 22   P22    150    123    101    113
## 23   P23     58     64     49     44
## 24   P24    515    495    437    430
## 25   P25    420    428    356    398
## 26   P26    143    155    108    129
## 27   P27    493    480    416    415
## 28   P28    460    424    401    411
## 29   P29    171    186    129    142
## 30   P30    491    453    378    368
## 31   P31    125    103    114    100
## 32   P32    138    116    112    107
## 33   P33    163    159    128    154
## 34   P34    518    505    443    466
## 35   P35    465    464    438    438
## 36   P36    531    491    405    416
## 37   P37    470    539    426    423
## 38   P38    606    462    412    412
## 39   P39    481    475    382    418
## 40   P40    514    503    416    431
## 41   P41    490    516    379    433
## 42   P42    447    485    366    372
## 43   P43    513    558    377    465
## 44   P44    420    489    395    388
## 45   P45    452    439    392    368
## 46   P46    502    460    352    402
## 47   P47    458    487    378    415
## 48   P48    488    495    393    428
## 49   P49    472    493    401    431
## 50   P50    129    110     99    121
## 51   P51    241    254    235    202
## 52   P52    495    475    330    415
## 53   P53     58     74     44     58
## 54   P54    525    479    406    450
## 55   P55    465    431    377    369
## 56   P56    497    440    357    407
## 57   P57    487    475    377    385
## 58   P58    451    472    393    422
## 59   P59    131    122     99    114
## 60   P60    478    479    381    377
## 61   P61    489    419    363    400
## 62   P62    232    223    190    189
## 63   P63    531    490    392    410
## 64   P64    467    465    356    361
## 65   P65    136    140    122     91
## 66   P66    516    489    425    412
## 67   P67    494    456    378    364
## 68   P68    128    128    104     82
## 69   P69    501    454    391    400
## 70   P70    466    448    364    390
## 71   P71    132    131    119    112
## 72   P72    482    535    389    407
## 73   P73    490    454    372    391
## 74   P74    128    135     93    113
## 75   P75    498    495    417    425
## 76   P76    481    465    362    375
## 77   P77     65     57     49     63
## 78   P78    482    486    359    334
## 79   P79    493    465    349    375
## 80   P80    456    467    341    334
## 81   P81    118    135     95    115
## 82   P82    132     99    100    113
## 83   P83    535    456    386    435
## 84   P84    477    478    389    408
## 85   P85    466    426    372    384
## 86   P86    472    426    391    415
## 87   P87    487    406    368    382
## 88   P88    474    428    370    354
## 89   P89    486    443    384    362
## 90   P90    517    415    385    392
## 91   P91    122    131    103    101
## 92   P92    506    552    421    417
## 93   P93    127    111    109    106
## 94   P94    107    136     99    115
## 95   P95    160    202    142    136
## 96   P96    480    487    396    440
## 97   P97    479    442    340    383
## 98   P98     54     66     31     59
## 99   P99    142    137     93    111
## 100 P100    127    179    104    169
## 101 P101    532    506    388    423
## 102 P102    434    461    375    373
## 103 P103    113    113    105     98
## 104 P104     74     45     41     46
## 105 P105     56     54     48     37
## 106 P106    149    152    119    137
## 107 P107    256    243    220    202
## 108 P108     27     42     36     43
## 109 P109    117    118    134    120
## 110 P110    134    114    112    101
## 111 P111     53     57     63     65
## 112 P112    495    467    435    411
## 113 P113    410    416    372    414
## 114 P114    133    120    122    112
## 115 P115    144    161    141    125
## 116 P116    123    137    103    122
## 117 P117     50     69     55     52
## 118 P118    147    153    102    100
## 119 P119    486    459    376    403
## 120 P120    446    462    375    443
## 121 P121    128    125    105    103
## 122 P122    112    130    109    113
## 123 P123     57     48     38     44
## 124 P124     67     64     46     63
## 125 P125    128    118     96     93
## 126 P126     63     46     54     62
## 127 P127     28     38     25     26
## 128 P128    519    452    406    448
## 129 P129    462    501    447    422
## 130 P130    525    464    402    374
## 131 P131    485    487    385    388
## 132 P132    511    477    408    423
## 133 P133    506    473    400    402
## 134 P134    478    489    438    436
## 135 P135    508    549    431    432
## 136 P136    516    488    410    445
## 137 P137    529    482    442    441
## 138 P138    443    435    394    391
## 139 P139    480    498    365    367
## 140 P140    462    436    431    406
## 141 P141    454    452    379    391
## 142 P142    459    434    349    421
## 143 P143    464    496    373    361
## 144 P144    149    131    106    107
## 145 P145    136    142    100     92
## 146 P146    135     94     95    115
## 147 P147    128    117    124    109
## 148 P148     55     42     46     58
## 149 P149    138    124    122    102
## 150 P150     50     59     43     53
## 151 P151     75     68     35     43
## 152 P152    128    117    104    125
## 153 P153    153    112    100    121
## 154 P154    117    124    110     83
## 155 P155     48     58     53     45
## 156 P156     56     43     44     44
## 157 P157    141    100     91     98
## 158 P158     59     44     32     45
## 159 P159     60     52     44     56
## 160 P160    137    105    107    124
## 161 P161     65     54     50     59
## 162 P162    134    128     94     93
## 163 P163     56     43     54     51
## 164 P164    117    133    110    105
## 165 P165    146    133    111    122
## 166 P166    134    133    115    120
## 167 P167    534    441    368    389
## 168 P168    495    474    416    401
## 169 P169    438    435    355    389
## 170 P170    426    447    403    435
## 171 P171    128    112    109     99
## 172 P172    493    490    418    403
## 173 P173    495    538    413    451
## 174 P174    522    508    391    465
## 175 P175    488    494    440    402
## 176 P176    499    490    381    342
## 177 P177    461    488    391    380
## 178 P178    511    562    405    447
## 179 P179    494    504    459    447
## 180 P180    521    484    418    430
## 181 P181    481    462    403    359
## 182 P182    458    421    342    416
## 183 P183    440    444    376    357
## 184 P184    496    513    392    382
## 185 P185    495    459    427    387
## 186 P186    500    492    405    402
## 187 P187    433    409    344    393
## 188 P188    487    443    360    388
## 189 P189    449    437    404    388
## 190 P190    549    500    433    430
## 191 P191    547    506    393    408
## 192 P192    443    470    374    397
## 193 P193    505    544    390    420
## 194 P194    461    432    338    382
## 195 P195     64     65     49     48
## 196 P196    492    408    386    411
## 197 P197    133    137    106    124
## 198 P198    137    166    109    120
## 199 P199     51     49     32     41
## 200 P200    228    275    165    237
## 201 P201     51     58     42     46
## 202 P202    167    247    164    227
## 203 P203     77     89     67     83
## 204 P204     22     38     34     28
## 205 P205    137    207    123    165
## 206 P206     27     42     23     45
## 207 P207     73     81     54     86
## 208 P208    404    517    293    431
## 209 P209    133    153    103    126
## 210 P210    170    192    125    166
## 211 P211    165    172    127    125
## 212 P212      3      4      7      8
## 213 P213      2      1      3      6
## 214 P214      2      2      6      3
## 215 P215      0      1      0      0
## 216 P216      0      1      5      4
## 217 P217      0      0      1      6
## 218 P218      1      0      0      4
## 219 P219      3      2      8      3
## 220 P220      0      1      5      7
## 221 P221      0      3      2     10
## 222 P222      2      2      4      3
## 223 P223      1      5      1      3
## 224 P224      4      5      3     12
## 225 P225      3      0      2      7
## 226 P226      1      4      2      2
## 227 P227      2      2      0      2
## 228 P228      1      0      0      1
## 229 P229      3      1      2      3
## 230 P230      1      0      0      1
## 231 P231      2      1      0      6
## 232 P232      0      1      1      1
## 233 P233      0      3      1      2
## 234 P234      1      1      0      2
## 235 P235      1      4      1      2
## 236 P236      0      2      2      1
## 237 P237      0      2      2      1
## 238 P238      1      4      1      8
## 239 P239      4      3      2      2
## 240 P240      1      4      2      4
## 241 P241      2      3      3      5
## 242 P242      1      3      0      8
## 243 P243      0      2      0      2
## 244 P244      3      2      1      3
## 245 P245      4      6      0      4
## 246 P246      0      4      2      1
## 247 P247      4      9      2      4
## 248 P248      0      5      3      4
## 249 P249      1      1      1      1
## 250 P250      0      1      0      1
## 251 P251      0      0      0      1
## 252 P252      0      0      1      7
## 253 P253      0      0      0      2
## 254 P254      1      0      0      0
## 255 P255      4     13     11     27
## 256 P256      1      0      1      2
## 257 P257      7     11      7      9
## 258 P258      0      2      3      0
## 259 P259      0      1      0      0
## 260 P260      2      3      0      0
## 261 P261    285    318    216    250
## 262 P262    400    534    291    456
## 263 P263    228    304    172    235
## 264 P264    131    149     92    118
## 265 P265     22     32     10     39
## 266 P266    136    125    106    125
## 267 P267    129    123    119    115
## 268 P268    237    276    186    261
## 269 P269    140    203    127    170
## 270 P270    264    309    218    239
## 271 P271     55     46     35     45
## 272 P272      4      6      6      5
## 273 P273      1      2      2      5
## 274 P274      1      1      0      5
## 275 P275      1      0      0      3
## 276 P276      1      0      0      2
## 277 P277      0      3      4      7
## 278 P278      1      1      2      3
## 279 P279      0      1      1      0
## 280 P280      1      4      0      2
## 281 P281      9     19     10     12
## 282 P282      7      6      9     11
## 283 P283      1      5      9     12
## 284 P284    257    262    189    222
## 285 P285    127    145     92    114
## 286 P286    225    314    178    243
## 287 P287      7     16     16     22
## 288 P288      9     12     14      9
## 289 P289      4      5      3      9
## 290 P290      4      0      5      5
## 291 P291     42     57     40     44
## 292 P292     56     42     51     44
## 293 P293     47     63     40     47
## 294 P294    148    144     94     99
## 295 P295     54     74     31     72
## 296 P296     55     55     49     60
## 297 P297     49     59     40     56
## 298 P298     65     53     33     54
## 299 P299    120    126     98    130
## 300 P300     64     43     57     59
## 301 P301     51     56     49     56
## 302 P302     59     46     55     57
## 303 P303     59     57     32     52
## 304 P304    113    120     95    102
## 305 P305     75     62     61     58
## 306 P306     68     53     44     47
## 307 P307     58     58     57     54
## 308 P308     58     56     43     50
## 309 P309    119    144     99    120
## 310 P310     48     67     64     53
## 311 P311     67     53     54     52
## 312 P312     45     54     57     56
## 313 P313     66     48     44     62
## 314 P314    159    136     90    119
## 315 P315     56     57     46     48
## 316 P316     69     60     49     41
## 317 P317     60     64     54     48
## 318 P318     69     42     30     50
## 319 P319    125    141    112     96
## 320 P320     64     53     48     54
## 321 P321     61     45     54     56
## 322 P322     62     57     37     37
## 323 P323     61     58     46     46
## 324 P324    134    139    101     98
## 325 P325     62     52     48     52
## 326 P326     70     65     47     30
## 327 P327     52     51     52     47
## 328 P328     55     69     40     45
## 329 P329     74     55     49     53
## 330 P330     58     57     39     55
## 331 P331     71     69     62     44
## 332 P332    141    127    102     90
## 333 P333    134    138     93    108
## 334 P334    154    145    104    110
## 335 P335     46     40     41     42
## 336 P336     42     55     36     49
## 337 P337     44     61     44     52
## 338 P338     35     36     20     45
## 339 P339     15     12     17     19
## 340 P340      1      3      9     17
## 341 P341     41     44     43     40
## 342 P342     25     39     20     36
## 343 P343     16     33     19     35
## 344 P344     15     21     19     27
## 345 P345     31     25     29     48
## 346 P346      1      5      5      6
## 347 P347      3      4      6      7
## 348 P348      5      4      9      5
## 349 P349      0      6      5      5
## 350 P350      0      2      2      4
## 351 P351      0      2      0      1
## 352 P352      1      2      1      2
## 353 P354      0      1      1      2
## 354 P355      1      0      1      2
## 355 P356     50     51     38     58
## 356 P357     35     32     20     27
## 357 P358      6     10     13     35
## 358 P359     62     81     54     68
## 359 P360     11     14      8     18
## 360 P361     28     40     27     37
## 361 P362      8     17     14     21
## 362 P363      6      6      6      9
## 363 P364    156    200    131    169
## 364 P365     54     55     37     45
## 365 P366     40     39     36     44
## 366 P367     24     37     20     36
## 367 P368     55     86     46     93
## 368 P369     48     75     36     45
## 369 P370     53     59     32     41
## 370 P371     27     35     18     34
## 371 P372     19     36     13     43
## 372 P373     17      5     24     29
## 373 P374     14     11     15     19
## 374 P375      7      6      8      9
## 375 P376      2      9     10     10
## 376 P377      3      7     14      7
## 377 P378      1      3      7      9
## 378 P379      3      3      2      5
## 379 P380      0      0      0      3
## 380 P381      1      1      0      0
## 381 P382      0      1      0      1
## 382 P383      0      1      0      1
## 383 P384      3      4      2      7
## 384 P386      0      2      0      1
## 385 P387     51     46     27     43
## 386 P388     33     54     29     37
## 387 P389     20     44     28     37
## 388 P390     39     43     22     35
## 389 P391     24     45     24     42
## 390 P392     60     75     66     78
## 391 P393      9     15     19     27
## 392 P394     37     31     25     37
## 393 P395     19     41     27     35
## 394 P396     26     33     23     40
## 395 P397    121    179     92    110
## 396 P398    148    199    123    154
## 397 P399    162    205    120    173
## 398 P400    196    264    129    229
## 399 P401     58     50     38     52
## 400 P402     34     56     45     35
## 401 P403    187    246    178    212
## 402 P404    129    133     97    113
## 403 P405    246    295    169    256
## 404 P406    180    205    115    191
## 405 P407    268    263    201    226
## 406 P408    137    192    116    180
## 407 P409    526    697    414    583
## 408 P410    192    276    155    237
## 409 P411    208    281    176    220
## 410 P412     45     53     39     45
## 411 P413    105    156     77    138
## 412 P414     44     47     34     42
## 413 P415     54     54     38     30
## 414 P416      9     12     12     24
## 415 P417      4      9      5      7
## 416 P418      1      4      5      6
## 417 P419      1      1      4      6
## 418 P420      1      2      1      1
## 419 P421      0      1      1      0
## 420 P422      8     10      7     16
## 421 P423      2      4      3      4
## 422 P424      3      5      1      7
## 423 P425      0      1      3      0
## 424 P426      1      3      1      1
## 425 P427      3      1      2      3
## 426 P428      0      1      0      1
## 427 P429    122    136     82    117
## 428 P430    166    172    131    174
## 429 P431     85    103     53     78
## 430 P432     86    126     80    122
## 431 P433     45     63     43     61
## 432 P434     28     36     25     47
## 433 P435    209    262    199    197
## 434 P436    110    154     84    114
## 435 P437     88     95     64     71
## 436 P438      6      3      7      7
## 437 P439      5      4      3     10
## 438 P440      4      3      3      5
## 439 P441      4      4      1      5
## 440 P442      4      2      5     10
## 441 P443      4      7      1      4
## 442 P444      0      2      1      1
## 443 P445      4      3      2      3
## 444 P446      3      2      1      6
## 445 P447      1      4      1      8
## 446 P448      7      1      6     11
## 447 P449      0      6      7      8
## 448 P450      5      1      6      5
## 449 P451      5      2      4      4
## 450 P452      5      5      2      3
## 451 P453      5      0      3      2
## 452 P454      2      1      1      4
## 453 P455      3      5     10      6
## 454 P456      3      6      2     14
## 455 P457      0      2      1      1
## 456 P458      1      5      1      6
## 457 P459      1      2      4      7
## 458 P460      3      4      4      8
## 459 P461      1      4      2      4
## 460 P462      1      0      3      3
## 461 P463      1      2      0      3
## 462 P464      1      4      1      1
## 463 P465      1      3      0      2
## 464 P466      0      1      0      2
## 465 P467      0      0      1      1
## 466 P468      0      0      0      2
## 467 P469      0      1      0      0
## 468 P470      0      3      0      4
## 469 P471      0      1      0      1
## 470 P472      3      4      3      2
## 471 P473      1      2      0      0
## 472 P474      0      1      0      2
## 473 P475     30     44     29     30
## 474 P476     14      8     10     27
## 475 P477     10      7     10     13
## 476 P478      9     18     10     18
## 477 P479      8      9     13     17
## 478 P480      1      6      9      5
## 479 P481     10     21     18     20
## 480 P482      4     11      6     12
## 481 P483      4      3      6      4
## 482 P484     63     59     47     59
## 483 P485    148    132    107    113
## 484 P486    276    252    206    211
## 485 P487    160    187    146    132
## 486 P488    143    175    114    127
## 487 P489     73     71     38     48
## 488 P490    108    125     86    114
## 489 P491    262    251    189    225
## 490 P492    140    163    118    135
## 491 P493    139    167    120    131
## 492 P494    166    181    138    128
## 493 P495    221    239    156    210
## 494 P496    140    127     76    124
## 495 P497     56     65     49     62
## 496 P498     70     48     47     34
## 497 P499    139    125     94     99
## 498 P500    100     84     80     60
## 499 P501     71     81     59     54
## 500 P502    176    173    137    165
## 501 P503    202    230    147    232
## 502 P504    156    166    120    140
## 503 P505    216    230    161    190
## 504 P506    208    187    110    126
## 505 P507    227    294    161    193
## 506 P508    128    130     99     99
## 507 P509     79     84     60     71
## 508 P510    104    117     65     93
## 509 P511    363    364    274    288
## 510 P512    235    290    172    266
## 511 P513    269    257    188    208
## 512 P514    148    169    123    154
## 513 P515    135    151     94     98
## 514 P516    271    269    207    222
## 515 P517    170    182    123    127
## 516 P518    153    146    100    104
## 517 P519    292    270    184    221
## 518 P520    168    184    123    158
## 519 P521    149    141    107    129
## 520 P522    159    158    122    116
## 521 P523    171    180    106    134
## 522 P524    146    152     95    120
## 523 P525    163    182    147    143
## 524 P526    188    275    154    199
## 525 P527    163    142    120    140
## 526 P528    169    168     95    134
## 527 P529    179    183    141    155
## 528 P530    215    245    148    212
## 529 P531     59     67     61     67
## 530 P532    114    146    105    108
## 531 P533    345    362    260    286
## 532 P534    108    157    100    107
## 533 P535    245    277    171    256
## 534 P536    146    183    123    151
## 535 P537    248    271    193    208
## 536 P538    154    205    137    163
## 537 P539    132    140    104    106
## 538 P540    248    265    182    213
## 539 P541    142    156    118    140
## 540 P542    147    149    113    149
## 541 P543    141    169    104    123
## 542 P544    162    164    127    147
## 543 P545    215    263    167    184
## 544 P546    157    156    123    166
## 545 P547    142    146    113    124
## 546 P548    471    467    378    375
## 547 P549    473    469    331    362
## 548 P550    150    116    106    106
## 549 P551    122    135    118    101
## 550 P552    139    116     97    100
## 551 P553     53     56     52     41
## 552 P554    290    247    207    212
## 553 P555    142    163    122    110
## 554 P556    201    241    156    188
## 555 P557    399    356    264    296
## 556 P558    164    181    132    142
## 557 P559    153    171    128    134
## 558 P560    125    149     96    129
## 559 P561     60     63     36     44
## 560 P562     58     50     48     64
## 561 P563    130    123     83    114
## 562 P564    128    138    112    102
## 563 P565    120    117     90    114
## 564 P566    276    253    213    204
## 565 P567     61     51     49     38
## 566 P568     37     52     34     45
## 567 P569     38     46     25     30
## 568 P570     26     50     25     30
## 569 P571     67     87     51     72
## 570 P572     11     22     16     23
## 571 P573     36     61     36     36
## 572 P574      5      9      7      7
## 573 P575      3      4      6     10
## 574 P576      1      1      6      7
## 575 P577     10      6      6     17
## 576 P578      3      7      2      2
## 577 P579      1      2      4      1
## 578 P580     41     52     30     49
## 579 P581     48     36     32     47
## 580 P582     37     31     30     26
## 581 P583     33     39     28     40
## 582 P584     46     56     20     38
## 583 P585     14     21     10     24
## 584 P586     70    104     64     76
## 585 P587     38     60     39     48
## 586 P588     33     34     15     27
## 587 P589      9     19     22     27
## 588 P590     43     65     31     49
## 589 P591     32     41     28     38
## 590 P592      9     16     13     25
## 591 P593     43     54     29     48
## 592 P594     37     59     28     47
## 593 P595     35     43     18     42
## 594 P596     55    100     52     78
## 595 P597     10     14     11     33
## 596 P598    147    204    112    173
## 597 P599     23     43     53     80
## 598 P600     16     23     26     49
## 599 P601      7     21     31     28
## 600 P602      9     10     13      9
## 601 P603      4      5     10     10
## 602 P604      2      4      6      2
## 603 P605     15     15     12     21
## 604 P606     10      9     14     11
## 605 P607      2      3      3      5
## 606 P608      5      4      2     12
## 607 P609     38     63     36     42
## 608 P610     54     55     37     49
## 609 P611     37     53     40     55
## 610 P612    186    199    121    175
## 611 P613    286    342    209    316
## 612 P614     60     90     54     80
## 613 P615    298    383    226    358
## 614 P616     56     85     47     66
## 615 P617    496    420    380    360
## 616 P618    512    437    422    411
## 617 P619    456    431    419    366
## 618 P620    429    439    352    373
## 619 P621    477    454    361    406
## 620 P622    451    440    383    419
## 621 P623    449    425    390    409
## 622 P624    140    114    105    103
## 623 P625    135    119    116    116
## 624 P626    133    105    105    121
## 625 P627    143    122    108    139
## 626 P628    119    105    109    104
## 627 P629    123    128    129    102
## 628 P630    143    109    103     95
## 629 P631    147    117    106     90
## 630 P632    131    168    110    111
## 631 P633    124    161     93    113
## 632 P634    138    157    109    114
## 633 P635    149    111    119     84
## 634 P636    144    171    122    156
## 635 P637     42     60     53     65
## 636 P638    175    208    103    181
## 637 P639      2      2      3      3
## 638 P640    197    260    190    220
## 639 P641     35     31     30     34
## 640 P642     44     57     33     43
## 641 P643      0      4      1      0
## 642 P644      0      1      1      0
## 643 P646      0      1      0      1
## 644 P647      1      3      1      1
## 645 P649      0      0      1      1
## 646 P650      0      2      0      1
## 647 P651      2      6      5      6
## 648 P652      0      3      1      6
## 649 P653      2      3      3      5
## 650 P654      0      0      0      2
## 651 P655      1      3      1      1
## 652 P656      0      1      0      1
## 653 P657      0      0      2      4
## 654 P658      2      1      1      4
## 655 P659      1      1      2      2
## 656 P660      1      2      1      3
## 657 P661      2      0      1      0
## 658 P662      0      0      0      4
## 659 P663      3     11     12     12
## 660 P664      2      6      4     10
## 661 P665      1      6      3      3
## 662 P666      3      5      0      3
## 663 P667      4      3      2      2
## 664 P668      1      1      1      0
## 665 P669      1      2      1      1
## 666 P670      4     10     11     14
## 667 P671      3      5      1      9
## 668 P672      0      4      1      6
## 669 P673     26     38     42     54
## 670 P674     62     89     91    139
## 671 P675     28     62     58     81
## 672 P676     30     40     38     54
## 673 P677      1      2      1      1
## 674 P678      1      2      1      2
## 675 P679      2      3      1      3
## 676 P680      0      1      0      0
## 677 P681      2      1      0      4
## 678 P682      1      0      0      3
## 679 P683      0      2      0      2
## 680 P684      0      0      0      1
## 681 P685      0      2      0      2
## 682 P686     22     48     27     36
## 683 P687     13      8     18     14
## 684 P688      6      8     11      7
## 685 P689      3      2      5     11
## 686 P690      3      6      6      8
## 687 P691      1      6      3      4
## 688 P692     25     45     11     37
## 689 P693     35     31     24     43
## 690 P694      0      2      3     11
## 691 P695      1      4      1      7
## 692 P696      1      4      1      5
## 693 P697      1      6      3     13
## 694 P698     27     39     28     27
## 695 P699      6     17      9     20
## 696 P700     13      6      8     19
## 697 P701     41     48     26     43
## 698 P702     62     77     69     93
## 699 P703     26     25     39     67
## 700 P704      6      8     12     13
## 701 P705     31     39     24     42
## 702 P706     10     15     16     25
## 703 P707      2      6     12     18
## 704 P708      1      0      1      0
## 705 P711      1      4      3      1
## 706 P712      0      1      0      2
## 707 P713      2      1      1      0
## 708 P714      2      2      3      0
## 709 P715      2      2      0      0
## 710 P716      2      1      0      0
## 711 P717      1      2      2      3
## 712 P718      6      2      3      5
## 713 P719      0      0      2      1
## 714 P720      0      6      0      2
## 715 P721      0      1      0      0
## 716 P722      0      1      0      1
## 717 P724      1      2      0      2
## 718 P726     12     12     16     18
## 719 P727     32     20     54     52
## 720 P728      5     10     11     15
## 721 P729      0      4      1      7
## 722 P730      2      0      2      1
## 723 P731      3      3      4      6
## 724 P732     12      9     18     31
## 725 P733      3      7     10     17
## 726 P734      4      4      7      7
## 727 P735      0      3      6      9
## 728 P736      9     14     16     23
## 729 P737     20     32     46     47
## 730 P738      3      8      8     16
## 731 P739      4      2      5      5
## 732 P740      1      2      2      5
## 733 P741      1      3      2      6
## 734 P742      7     14     10     21
## 735 P743      9     10      9     21
## 736 P744      1      2      2      4
## 737 P745     53     76     62     81
## 738 P746     13     11     15     24
## 739 P747     31     36     30     54
## 740 P748      7      7      3     18
## 741 P749      4     10      8     13
## 742 P750      2      3      6      7
## 743 P751      6      2      4      9
## 744 P752     25     39     18     28
## 745 P753      8     12     11     16
## 746 P754      5     14     12     18
## 747 P755      3      7      5      7
## 748 P756      5      3      1      8
## 749 P757      1      4      0     10
## 750 P758      0      3      0      9
## 751 P759      1      1      1      7
## 752 P760      0      1      0      1
## 753 P761      0      2      1      0
## 754 P762     18     23     16     32
## 755 P763      1      1      0      0
## 756 P764     25     49     27     64
## 757 P765      5      3     14     19
## 758 P766      4      6      6      9
## 759 P767      8     17     17     25
## 760 P768     35     51     46     74
## 761 P769     10     22     13     24
## 762 P770      5      2      3      5
## 763 P771      1      4      3      7
## 764 P772      2      3      5      4
## 765 P773      2      3      1      3
## 766 P774      0      3      1      2
## 767 P775      0      0      0      4
## 768 P776      2      4      6      4
## 769 P777      1      3      2      5
## 770 P778      0      1      1      6
## 771 P779      1      2      3      6
## 772 P780      0      7      1      0
## 773 P781    196    259    163    237
## 774 P782     52     46     45     46
## 775 P783    174    192    149    172
## 776 P784     29     57     36     54
## 777 P785     24     34     18     35
## 778 P786     32     27     29     30
## 779 P787     12      9     20     27
## 780 P788     43     48     33     53
## 781 P789     32     52     26     54
## 782 P790     31     42     26     27
## 783 P791     60     92     53     82
## 784 P792     14     13     23     24
## 785 P793     21     38     39     59
## 786 P794      4      2      9     19
## 787 P795      3      4      9      7
## 788 P796     39     58     30     46
## 789 P797     32     56     20     45
## 790 P798     25     34     28     32
## 791 P799     47     79     48     77
## 792 P800      9     16     22     29
## 793 P801     32     34     32     52
## 794 P802      9      8      6     15
## 795 P803     37     58     41     49
## 796 P804     32     48     31     41
## 797 P805     36     45     24     33
## 798 P806     61     64     55     89
## 799 P807      7     21     13     27
## 800 P808     27     38     40     57
## 801 P809      7     13      8     12
## 802 P810      2      1     11      6
## 803 P811     44     50     44     46
## 804 P812     24     18     15     23
## 805 P813     27     44     22     29
## 806 P814     58     69     54     85
## 807 P815      6      6      3      8
## 808 P816     17     27     37     61
## 809 P817      8      2      2     14
## 810 P818      2      5      6      4
## 811 P819      1      5      8      2
Qtr.Sls.By.Prdt$Q1.Sls <- as.numeric(Qtr.Sls.By.Prdt$Q1.Sls)
Qtr.Sls.By.Prdt$Q2.Sls <- as.numeric(Qtr.Sls.By.Prdt$Q2.Sls)
Qtr.Sls.By.Prdt$Q3.Sls <- as.numeric(Qtr.Sls.By.Prdt$Q3.Sls)
Qtr.Sls.By.Prdt$Q4.Sls <- as.numeric(Qtr.Sls.By.Prdt$Q4.Sls)

#Top5 Product by Q1 Sale
TopQ1.Prdt.Sls <- Qtr.Sls.By.Prdt %>% 
    select(Prdt,Q1.Sls) %>% filter(Prdt %in% c("P409", "P34" , "P178" ,"P135", "P43")) %>% arrange(desc(Q1.Sls)) %>% top_n(5,Q1.Sls)

TopQ2.Prdt.Sls <- Qtr.Sls.By.Prdt %>% 
    select(Prdt,Q2.Sls) %>%  filter(Prdt %in% c("P409", "P34" , "P178" ,"P135", "P43")) %>% arrange(desc(Q2.Sls)) %>% top_n(5,Q2.Sls)
  
TopQ3.Prdt.Sls <- Qtr.Sls.By.Prdt %>% 
    select(Prdt,Q3.Sls) %>%  filter(Prdt %in% c("P409", "P34" , "P178" ,"P135", "P43")) %>% arrange(desc(Q3.Sls)) %>% top_n(5,Q3.Sls)
  
TopQ4.Prdt.Sls <- Qtr.Sls.By.Prdt %>% 
    select(Prdt,Q4.Sls) %>%  filter(Prdt %in% c("P409", "P34" , "P178" ,"P135", "P43")) %>% arrange(desc(Q4.Sls)) %>% top_n(5,Q4.Sls)
    

# Plot top 5 Product by Sale
p1<- ggplot(TopQ1.Prdt.Sls, aes(x=reorder(Prdt,-Q1.Sls), y= Q1.Sls)) + 
  geom_bar(stat="identity", width=.5, fill="tomato3") + 
  labs(title="Top 5 Products by Q1 Sale", 
       subtitle="Q1 Quarter", 
       caption="Product:Sales",
       y="Total Sales",
       x="Product") + 
  theme(axis.text.x = element_text(angle=65, vjust=0.6))

p2<- ggplot(TopQ2.Prdt.Sls, aes(x=reorder(Prdt,-Q2.Sls), y= Q2.Sls)) + 
  geom_bar(stat="identity", width=.5, fill="tomato3") + 
  labs(title="Top 5 Products by Q2 Sale", 
       subtitle="Q2 Quarter", 
       caption="Product:Sales",
       y="Total Sales",
       x="Product") + 
  theme(axis.text.x = element_text(angle=65, vjust=0.6))

p3<- ggplot(TopQ3.Prdt.Sls, aes(x=reorder(Prdt,-Q3.Sls), y= Q3.Sls)) + 
  geom_bar(stat="identity", width=.5, fill="tomato3") + 
  labs(title="Top 5 Products by Q3 Sale", 
       subtitle="Q3 Quarter", 
       caption="Product:Sales",
       y="Total Sales",
       x="Product") + 
  theme(axis.text.x = element_text(angle=65, vjust=0.6))

p4<- ggplot(TopQ4.Prdt.Sls, aes(x=reorder(Prdt,-Q4.Sls), y= Q4.Sls)) + 
  geom_bar(stat="identity", width=.5, fill="tomato3") + 
  labs(title="Top 5 Products by Q4 Sale", 
       subtitle="Q4 Quarter", 
       caption="Product:Sales",
       y="Total Sales",
       x="Product") + 
  theme(axis.text.x = element_text(angle=65, vjust=0.6))

library(gridExtra)
grid.arrange(p1, p2,p3,p4, ncol = 4)

#Total Sales by different buckets
Tot.Sls.Bkt<- Tot.Sls.By.Prdt %>%
  select(Prdt,Yr.Sls) %>%
  mutate(High=ifelse(Yr.Sls >575,1,0 ), Mid=ifelse(Yr.Sls>199 & Yr.Sls < 575,1,0),Low=ifelse(Yr.Sls>1 & Yr.Sls < 199,1,0) ) %>%
  arrange(desc(Yr.Sls))
 
Sls.Bkt<- Tot.Sls.Bkt %>% select(High,Mid,Low) %>% summarise(High=sum(High),Mid=sum(Mid),Low=sum(Low))

Sls.Bkt.Plot<- as.data.frame(t(as.matrix(Sls.Bkt)))
names(Sls.Bkt.Plot)[1] <- "count"
bkt<- rownames(Sls.Bkt.Plot) 

Sls.Bkt.Plot <- cbind(bkt,Sls.Bkt.Plot)
rownames(Sls.Bkt.Plot) <- NULL


ggplot(Sls.Bkt.Plot, aes('', count, fill = bkt)) + 
  geom_col(position = 'fill') +
  geom_label(aes(label = paste(format(round( (count/sum(count))*100, 2), nsmall = 2),"%")), position = position_fill(vjust = 0.6)) +
  coord_polar(theta = 'y')+
  labs(x = NULL, y = NULL, fill = "Category", title = "Product % by Different Buckets")

#Plot the Sales counts by different buckets
Tol.Sls.Count.Bkt <- data.frame(Tot.Sls.Bkt %>% select(Yr.Sls,High) %>% filter(High==1) %>% summarise(Highcount=sum(Yr.Sls)),
Tot.Sls.Bkt %>% select(Yr.Sls,Mid) %>% filter(Mid==1) %>% summarise(Midcount=sum(Yr.Sls)) ,
Tot.Sls.Bkt %>% select(Yr.Sls,Low) %>% filter(Low==1) %>% summarise(Lowcount=sum(Yr.Sls))  )  
Tol.Sls.Count.Bkt<- as.data.frame(t(as.matrix(Tol.Sls.Count.Bkt)))
names(Tol.Sls.Count.Bkt)[1] <- "count"
count.bkt<- c("High Count","Mid Count", "Low Count")
Tol.Sls.Count.plot <- cbind(count.bkt,Tol.Sls.Count.Bkt)
rownames(Tol.Sls.Count.plot) <- NULL
ggplot(Tol.Sls.Count.plot, aes('', count, fill = count.bkt)) + 
  geom_col(position = 'fill') +
  geom_label(aes(label = paste(format(round( (count/sum(count))*100, 2), nsmall = 2),"%")), position = position_fill(vjust = 0.6)) +
  coord_polar(theta = 'y')+
  labs(x = NULL, y = NULL, fill = "Category", title = "Sales by Different Buckets")

#High Product Group Analysis
High.Prdt.List<- Tot.Sls.Bkt %>% select(Prdt,High) %>% filter(High==1)
head(High.Prdt.List)
##   Prdt High
## 1 P409    1
## 2  P34    1
## 3 P178    1
## 4 P135    1
## 5  P43    1
## 6 P190    1
High.Dtl.Data<- Data.Copy %>% filter(Product_Code %in% c("P409","P34","P178","P135","P43","P190","P179","P173","P92","P137","P38","P174","P24","P16","P40","P54","P136","P193","P37","P191","P180","P101","P36","P66","P134","P75","P129","P128","P175","P63","P132","P41","P72","P83","P112","P15","P35","P27","P48","P172","P96","P186","P49","P168","P184","P618","P133","P185","P17","P130","P39","P84","P69","P131","P47","P58","P140","P167","P120","P57","P119","P177","P46","P52","P60","P176","P170","P139","P90","P73","P181","P86","P56","P621","P196","P28","P143","P622","P44","P67","P548","P30","P19","P192","P76","P18","P79","P262","P188","P189","P141","P89","P623","P619","P61","P42","P70","P138","P142","P78","P617","P45","P64","P85","P208","P97","P87","P102","P55","P182","P549","P88","P169","P183","P194","P113","P25","P80","P620","P187","P557","P511","P615","P533","P613","P261","P270","P10","P516","P519","P405","P512","P268","P286","P407","P554","P535","P566","P486","P263","P51","P284","P491","P513","P107","P537","P540","P200","P411","P507","P435","P640","P410","P781","P62","P545","P495","P403","P530","P400","P526","P503","P202","P505","P556","P406","P783","P612","P638","P399","P538","P529","P364","P210","P502","P430","P95","P269","P598","P525","P520","P205","P506","P29","P408","P487","P398","P558","P14","P494","P33","P536","P517","P546","P11","P544","P514","P636","P523","P211","P559","P504","P100")
)
head(High.Dtl.Data)
##   Product_Code W0 W1 W2 W3 W4 W5 W6 W7 W8 W9 W10 W11 W12 W13 W14 W15 W16
## 1          P10 22 19 19 29 20 16 26 20 24 20  31  22  23  19  15  19  22
## 2          P11 15  7 15 14 17  7 10 16 11  8   8  10  10  12  10  16  13
## 3          P14 14 12  9 11 13 12  8 12 13 10  10  17  14  14  25  18  13
## 4          P15 19 45 47 42 29 44 43 36 25 52  39  42  43  42  43  51  40
## 5          P16 30 27 27 43 29 32 49 41 49 38  42  30  43  43  54  48  34
## 6          P17 49 40 40 28 40 47 44 45 39 33  39  37  33  52  29  45  34
##   W17 W18 W19 W20 W21 W22 W23 W24 W25 W26 W27 W28 W29 W30 W31 W32 W33 W34
## 1  23  20  33  16  23  23  16  25  27  12  15  15  11  14  29  23  12  16
## 2  10  13  13  18  12  15   9   8   5  11   8   9  10   7  12  12   9  16
## 3  22  12  21  15  17  11  15  12  17  11   5   7   7   8   9   5  11   9
## 4  44  30  39  39  36  32  39  30  22  25  34  28  29  24  29  25  38  40
## 5  36  44  43  44  28  35  29  43  30  27  30  29  35  42  39  38  38  38
## 6  43  40  50  29  36  32  28  35  30  22  23  20  17  24  26  20  30  28
##   W35 W36 W37 W38 W39 W40 W41 W42 W43 W44 W45 W46 W47 W48 W49 W50 W51 MIN
## 1   9  23  22  15  18  13  17  14  17  11  24  13  16  18  23  18  20   9
## 2  11  12  10   6  19   6  12  11  16  12  11  13   8  17  10  10  21   5
## 3   8  13  12   7   8  12   7  14   6   3   9  15   8  11  13  12  18   3
## 4  36  42  22  33  30  21  31  38  35  33  30  37  30  30  34  38  20  19
## 5  34  32  31  33  32  36  34  40  30  33  39  42  45  31  31  23  22  22
## 6  35  41  29  35  30  40  28  36  31  36  35  43  28  30  30  26  25  17
##   MAX Normalized.0 Normalized.1 Normalized.2 Normalized.3 Normalized.4
## 1  33         0.54         0.42         0.42         0.83         0.46
## 2  21         0.63         0.13         0.63         0.56         0.75
## 3  25         0.50         0.41         0.27         0.36         0.45
## 4  52         0.00         0.79         0.85         0.70         0.30
## 5  54         0.25         0.16         0.16         0.66         0.22
## 6  52         0.91         0.66         0.66         0.31         0.66
##   Normalized.5 Normalized.6 Normalized.7 Normalized.8 Normalized.9
## 1         0.29         0.71         0.46         0.63         0.46
## 2         0.13         0.31         0.69         0.38         0.19
## 3         0.41         0.23         0.41         0.45         0.32
## 4         0.76         0.73         0.52         0.18         1.00
## 5         0.31         0.84         0.59         0.84         0.50
## 6         0.86         0.77         0.80         0.63         0.46
##   Normalized.10 Normalized.11 Normalized.12 Normalized.13 Normalized.14
## 1          0.92          0.54          0.58          0.42          0.25
## 2          0.19          0.31          0.31          0.44          0.31
## 3          0.32          0.64          0.50          0.50          1.00
## 4          0.61          0.70          0.73          0.70          0.73
## 5          0.63          0.25          0.66          0.66          1.00
## 6          0.63          0.57          0.46          1.00          0.34
##   Normalized.15 Normalized.16 Normalized.17 Normalized.18 Normalized.19
## 1          0.42          0.54          0.58          0.46          1.00
## 2          0.69          0.50          0.31          0.50          0.50
## 3          0.68          0.45          0.86          0.41          0.82
## 4          0.97          0.64          0.76          0.33          0.61
## 5          0.81          0.38          0.44          0.69          0.66
## 6          0.80          0.49          0.74          0.66          0.94
##   Normalized.20 Normalized.21 Normalized.22 Normalized.23 Normalized.24
## 1          0.29          0.58          0.58          0.29          0.67
## 2          0.81          0.44          0.63          0.25          0.19
## 3          0.55          0.64          0.36          0.55          0.41
## 4          0.61          0.52          0.39          0.61          0.33
## 5          0.69          0.19          0.41          0.22          0.66
## 6          0.34          0.54          0.43          0.31          0.51
##   Normalized.25 Normalized.26 Normalized.27 Normalized.28 Normalized.29
## 1          0.75          0.13          0.25          0.25          0.08
## 2          0.00          0.38          0.19          0.25          0.31
## 3          0.64          0.36          0.09          0.18          0.18
## 4          0.09          0.18          0.45          0.27          0.30
## 5          0.25          0.16          0.25          0.22          0.41
## 6          0.37          0.14          0.17          0.09          0.00
##   Normalized.30 Normalized.31 Normalized.32 Normalized.33 Normalized.34
## 1          0.21          0.83          0.58          0.13          0.29
## 2          0.13          0.44          0.44          0.25          0.69
## 3          0.23          0.27          0.09          0.36          0.27
## 4          0.15          0.30          0.18          0.58          0.64
## 5          0.63          0.53          0.50          0.50          0.50
## 6          0.20          0.26          0.09          0.37          0.31
##   Normalized.35 Normalized.36 Normalized.37 Normalized.38 Normalized.39
## 1          0.00          0.58          0.54          0.25          0.38
## 2          0.38          0.44          0.31          0.06          0.88
## 3          0.23          0.45          0.41          0.18          0.23
## 4          0.52          0.70          0.09          0.42          0.33
## 5          0.38          0.31          0.28          0.34          0.31
## 6          0.51          0.69          0.34          0.51          0.37
##   Normalized.40 Normalized.41 Normalized.42 Normalized.43 Normalized.44
## 1          0.17          0.33          0.21          0.33          0.08
## 2          0.06          0.44          0.38          0.69          0.44
## 3          0.41          0.18          0.50          0.14          0.00
## 4          0.06          0.36          0.58          0.48          0.42
## 5          0.44          0.38          0.56          0.25          0.34
## 6          0.66          0.31          0.54          0.40          0.54
##   Normalized.45 Normalized.46 Normalized.47 Normalized.48 Normalized.49
## 1          0.63          0.17          0.29          0.38          0.58
## 2          0.38          0.50          0.19          0.75          0.31
## 3          0.27          0.55          0.23          0.36          0.45
## 4          0.33          0.55          0.33          0.33          0.45
## 5          0.53          0.63          0.72          0.28          0.28
## 6          0.51          0.74          0.31          0.37          0.37
##   Normalized.50 Normalized.51
## 1          0.38          0.46
## 2          0.31          1.00
## 3          0.41          0.68
## 4          0.58          0.03
## 5          0.03          0.00
## 6          0.26          0.23
High_Prod_Name <- High.Dtl.Data$Product_Code
rownames(High.Dtl.Data) <- High.Dtl.Data$Product_Code
High.Dtl.Data$Product_Code<- NULL
High.Dtl.Data.Bskt<- as.data.frame(t(as.matrix(High.Dtl.Data)))
High.Dtl.Data.Bskt <- High.Dtl.Data.Bskt[1:52,]

#Created a dataframe with total sales at product level
Tot.Sls.High.Bskt <- as.data.frame(colSums(High.Dtl.Data.Bskt[,c(1:203)])) 
names(Tot.Sls.High.Bskt)[1] <- "Yr.Sls"
Tot.Sls.By.Prdt <- cbind(Prdt,Tot.Sls.By.Prdt)
rownames(Tot.Sls.By.Prdt) <- NULL
summary(Tot.Sls.High.Bskt)
##      Yr.Sls      
##  Min.   : 579.0  
##  1st Qu.: 863.5  
##  Median :1651.0  
##  Mean   :1360.6  
##  3rd Qu.:1754.0  
##  Max.   :2220.0
hist(Tot.Sls.High.Bskt$Yr.Sls, main = "No of Product vs Sales Distribution on High Category", xlab = "Sale")

boxplot(Tot.Sls.High.Bskt$Yr.Sls, main = "Plot", names = c("High"))

#Low Product Group Analysis
Low.Prdt.List<- Tot.Sls.Bkt %>% select(Prdt,Low) %>% filter(Low==1)
head(Low.Prdt.List)
##   Prdt Low
## 1 P401   1
## 2 P201   1
## 3 P293   1
## 4 P356   1
## 5 P105   1
## 6 P610   1
Low.Prdt.List$Prdt
##   [1] P401 P201 P293 P356 P105 P610 P292 P322 P318 P365 P782 P590 P123 P156
##  [15] P370 P587 P611 P803 P811 P291 P336 P412 P271 P158 P609 P642 P788 P415
##  [29] P784 P593 P199 P796 P580 P594 P402 P335 P573 P341 P568 P387 P414 P764
##  [43] P789 P581 P676 P808 P584 P673 P366 P701 P727 P703 P793 P388 P797 P804
##  [57] P747 P801 P108 P737 P816 P583 P390 P569 P591 P595 P805 P206 P338 P434
##  [71] P705 P391 P345 P475 P686 P693 P361 P570 P394 P641 P389 P790 P582 P204
##  [85] P395 P396 P813 P698 P342 P798 P692 P786 P127 P367 P357 P371 P600 P372
##  [99] P785 P752 P588 P265 P343 P762 P601 P344 P812 P589 P800 P373 P792 P572
## [113] P393 P732 P481 P585 P769 P597 P787 P807 P767 P706 P358 P339 P592 P605
## [127] P746 P736 P287 P362 P374 P476 P726 P416 P255 P478 P687 P699 P742 P360
## [141] P281 P743 P754 P479 P753 P700 P288 P606 P422 P602 P728 P765 P477 P809
## [155] P577 P670 P704 P663 P707 P802 P733 P738 P748 P749 P257 P794 P282 P482
## [169] P688 P376 P377 P340 P375 P603 P574 P283 P363 P817 P417 P448 P456 P766
## [183] P224 P455 P348 P438 P575 P608 P690 P697 P795 P815 P212 P439 P664 P734
## [197] P755 P272 P289 P442 P449 P480 P689 P751 P347 P378 P810 P247 P460 P651
## [211] P671 P735 P750 P346 P450 P483 P756 P818 P219 P349 P384 P418 P424 P443
## [225] P694 P718 P731 P739 P776 P819 P221 P440 P451 P452 P576 P757 P770 P771
## [239] P238 P245 P277 P290 P441 P447 P459 P578 P604 P691 P772 P214 P220 P241
## [253] P379 P423 P458 P607 P653 P665 P695 P213 P225 P242 P248 P419 P445 P446
## [267] P472 P729 P741 P758 P779 P222 P239 P240 P461 P666 P667 P672 P696 P777
## [281] P216 P223 P273 P453 P639 P652 P740 P759 P226 P229 P231 P244 P427 P679
## [295] P711 P744 P773 P235 P252 P350 P454 P579 P658 P717 P720 P778 P780 P217
## [309] P246 P274 P278 P280 P462 P464 P470 P660 P681 P714 P227 P233 P352 P426
## [323] P463 P465 P647 P655 P657 P659 P678 P774 P218 P236 P237 P258 P260 P420
## [337] P643 P669 P677 P724 P730 P234 P243 P249 P256 P275 P354 P355 P425 P444
## [351] P457 P662 P682 P683 P685 P713 P715 P775 P232 P276 P351 P380 P386 P466
## [365] P473 P474 P650 P661 P668 P712 P716 P719 P761 P228 P230 P250 P253 P279
## [379] P381 P382 P383 P421 P428 P467 P468 P471 P644 P646 P649 P654 P656 P708
## [393] P722 P760 P763
## 811 Levels: P1 P10 P100 P101 P102 P103 P104 P105 P106 P107 P108 ... P99
Low.Dtl.Data<- Data.Copy %>% filter(Product_Code %in% c("P401","P201","P293","P356","P105","P610","P292","P322","P318","P365","P782","P590","P123","P156","P370","P587","P611","P803","P811","P291","P336","P412","P271","P158","P609","P642","P788","P415","P784","P593","P199","P796","P580","P594","P402","P335","P573","P341","P568","P387","P414","P764","P789","P581","P676","P808","P584","P673","P366","P701","P727","P703","P793","P388","P797","P804","P747","P801","P108","P737","P816","P583","P390","P569","P591","P595","P805","P206","P338","P434","P705","P391","P345","P475","P686","P693","P361","P570","P394","P641","P389","P790","P582","P204","P395","P396","P813","P698","P342","P798","P692","P786","P127","P367","P357","P371","P600","P372","P785","P752","P588","P265","P343","P762","P601","P344","P812","P589","P800","P373","P792","P572","P393","P732","P481","P585","P769","P597","P787","P807","P767","P706","P358","P339","P592","P605","P746","P736","P287","P362","P374","P476","P726","P416","P255","P478","P687","P699","P742","P360","P281","P743","P754","P479","P753","P700","P288","P606","P422","P602","P728","P765","P477","P809","P577","P670","P704","P663","P707","P802","P733","P738","P748","P749","P257","P794","P282","P482","P688","P376","P377","P340","P375","P603","P574","P283","P363","P817","P417","P448","P456","P766","P224","P455","P348","P438","P575","P608","P690","P697","P795","P815","P212","P439","P664","P734","P755","P272","P289","P442","P449","P480","P689","P751","P347","P378","P810","P247","P460","P651","P671","P735","P750","P346","P450","P483","P756","P818","P219","P349","P384","P418","P424","P443","P694","P718","P731","P739","P776","P819","P221","P440","P451","P452","P576","P757","P770","P771","P238","P245","P277","P290","P441","P447","P459","P578","P604","P691","P772","P214","P220","P241","P379","P423","P458","P607","P653","P665","P695","P213","P225","P242","P248","P419","P445","P446","P472","P729","P741","P758","P779","P222","P239","P240","P461","P666","P667","P672","P696","P777","P216","P223","P273","P453","P639","P652","P740","P759","P226","P229","P231","P244","P427","P679","P711","P744","P773","P235","P252","P350","P454","P579","P658","P717","P720","P778","P780","P217","P246","P274","P278","P280","P462","P464","P470","P660","P681","P714","P227","P233","P352","P426","P463","P465","P647","P655","P657","P659","P678","P774","P218","P236","P237","P258","P260","P420","P643","P669","P677","P724","P730","P234","P243","P249","P256","P275","P354","P355","P425","P444","P457","P662","P682","P683","P685","P713","P715","P775","P232","P276","P351","P380","P386","P466","P473","P474","P650","P661","P668","P712","P716","P719","P761","P228","P230","P250","P253","P279","P381","P382","P383","P421","P428","P467","P468","P471","P644","P646","P649","P654","P656","P708","P722","P760","P763")
)
head(Low.Dtl.Data)
##   Product_Code W0 W1 W2 W3 W4 W5 W6 W7 W8 W9 W10 W11 W12 W13 W14 W15 W16
## 1         P105  2  3  3  2  5  4  5  7  5  3   8   3   6   2   2   3   1
## 2         P108  0  2  2  0  3  1  2  1  6  3   0   3   4   3   5   1   5
## 3         P123  5  5  3  6  4  6  4  7  4  2   4   4   3   3   5   2   5
## 4         P127  4  0  2  2  2  1  3  2  1  3   1   0   7   2   6   1   4
## 5         P156  1  4  6  6  3  8  2  3  4  6   3   6   4   3   2   6   1
## 6         P158  8  3  3  2  3  3  4  5  2  7   7   3   9   3   4   6   3
##   W17 W18 W19 W20 W21 W22 W23 W24 W25 W26 W27 W28 W29 W30 W31 W32 W33 W34
## 1   7   6   5   6   7   3   4   5   3   3   2   8   4   2   6   2   5   5
## 2   0   1   2   2   3   4   9   2   5   3   2   0   3   3   0   2   4   0
## 3   1   0   5   4   6   5   5   0   7   5   0   5   1   3   5   5   0   2
## 4   0   3   7   7   3   2   0   2   1   1   3   2   3   4   2   2   0   0
## 5   5   5   0   4   0   5   4   4   4   2   6   5   3   2   2   7   4   1
## 6   2   4   2   6   2   5   2   2   3   5   1   3   1   0   6   1   3   1
##   W35 W36 W37 W38 W39 W40 W41 W42 W43 W44 W45 W46 W47 W48 W49 W50 W51 MIN
## 1   1   2   5   3   1   1   1   3   2   6   3   2   3   6   1   4   4   1
## 2   4   6   3   6   4   4   2   5   7   1   2   3   3   3   4   1   4   0
## 3   2   5   2   3   2   2   5   4   3   2   5   4   5   3   2   3   4   0
## 4   3   1   4   0   3   0   2   2   1   3   5   2   1   3   3   1   0   0
## 5   2   3   5   2   5   6   1   4   4   1   2   3   5   2   3   4   4   0
## 6   3   4   1   3   2   2   4   2   2   6   2   4   2   4   7   3   5   0
##   MAX Normalized.0 Normalized.1 Normalized.2 Normalized.3 Normalized.4
## 1   8         0.14         0.29         0.29         0.14         0.57
## 2   9         0.00         0.22         0.22         0.00         0.33
## 3   7         0.71         0.71         0.43         0.86         0.57
## 4   7         0.57         0.00         0.29         0.29         0.29
## 5   8         0.13         0.50         0.75         0.75         0.38
## 6   9         0.89         0.33         0.33         0.22         0.33
##   Normalized.5 Normalized.6 Normalized.7 Normalized.8 Normalized.9
## 1         0.43         0.57         0.86         0.57         0.29
## 2         0.11         0.22         0.11         0.67         0.33
## 3         0.86         0.57         1.00         0.57         0.29
## 4         0.14         0.43         0.29         0.14         0.43
## 5         1.00         0.25         0.38         0.50         0.75
## 6         0.33         0.44         0.56         0.22         0.78
##   Normalized.10 Normalized.11 Normalized.12 Normalized.13 Normalized.14
## 1          1.00          0.29          0.71          0.14          0.14
## 2          0.00          0.33          0.44          0.33          0.56
## 3          0.57          0.57          0.43          0.43          0.71
## 4          0.14          0.00          1.00          0.29          0.86
## 5          0.38          0.75          0.50          0.38          0.25
## 6          0.78          0.33          1.00          0.33          0.44
##   Normalized.15 Normalized.16 Normalized.17 Normalized.18 Normalized.19
## 1          0.29          0.00          0.86          0.71          0.57
## 2          0.11          0.56          0.00          0.11          0.22
## 3          0.29          0.71          0.14          0.00          0.71
## 4          0.14          0.57          0.00          0.43          1.00
## 5          0.75          0.13          0.63          0.63          0.00
## 6          0.67          0.33          0.22          0.44          0.22
##   Normalized.20 Normalized.21 Normalized.22 Normalized.23 Normalized.24
## 1          0.71          0.86          0.29          0.43          0.57
## 2          0.22          0.33          0.44          1.00          0.22
## 3          0.57          0.86          0.71          0.71          0.00
## 4          1.00          0.43          0.29          0.00          0.29
## 5          0.50          0.00          0.63          0.50          0.50
## 6          0.67          0.22          0.56          0.22          0.22
##   Normalized.25 Normalized.26 Normalized.27 Normalized.28 Normalized.29
## 1          0.29          0.29          0.14          1.00          0.43
## 2          0.56          0.33          0.22          0.00          0.33
## 3          1.00          0.71          0.00          0.71          0.14
## 4          0.14          0.14          0.43          0.29          0.43
## 5          0.50          0.25          0.75          0.63          0.38
## 6          0.33          0.56          0.11          0.33          0.11
##   Normalized.30 Normalized.31 Normalized.32 Normalized.33 Normalized.34
## 1          0.14          0.71          0.14          0.57          0.57
## 2          0.33          0.00          0.22          0.44          0.00
## 3          0.43          0.71          0.71          0.00          0.29
## 4          0.57          0.29          0.29          0.00          0.00
## 5          0.25          0.25          0.88          0.50          0.13
## 6          0.00          0.67          0.11          0.33          0.11
##   Normalized.35 Normalized.36 Normalized.37 Normalized.38 Normalized.39
## 1          0.00          0.14          0.57          0.29          0.00
## 2          0.44          0.67          0.33          0.67          0.44
## 3          0.29          0.71          0.29          0.43          0.29
## 4          0.43          0.14          0.57          0.00          0.43
## 5          0.25          0.38          0.63          0.25          0.63
## 6          0.33          0.44          0.11          0.33          0.22
##   Normalized.40 Normalized.41 Normalized.42 Normalized.43 Normalized.44
## 1          0.00          0.00          0.29          0.14          0.71
## 2          0.44          0.22          0.56          0.78          0.11
## 3          0.29          0.71          0.57          0.43          0.29
## 4          0.00          0.29          0.29          0.14          0.43
## 5          0.75          0.13          0.50          0.50          0.13
## 6          0.22          0.44          0.22          0.22          0.67
##   Normalized.45 Normalized.46 Normalized.47 Normalized.48 Normalized.49
## 1          0.29          0.14          0.29          0.71          0.00
## 2          0.22          0.33          0.33          0.33          0.44
## 3          0.71          0.57          0.71          0.43          0.29
## 4          0.71          0.29          0.14          0.43          0.43
## 5          0.25          0.38          0.63          0.25          0.38
## 6          0.22          0.44          0.22          0.44          0.78
##   Normalized.50 Normalized.51
## 1          0.43          0.43
## 2          0.11          0.44
## 3          0.43          0.57
## 4          0.14          0.00
## 5          0.50          0.50
## 6          0.33          0.56
Low_Prod_Name <- Low.Dtl.Data$Product_Code
rownames(Low.Dtl.Data) <- Low.Dtl.Data$Product_Code
Low.Dtl.Data$Product_Code<- NULL
Low.Dtl.Data.Bskt<- as.data.frame(t(as.matrix(Low.Dtl.Data)))
Low.Dtl.Data.Bskt <- Low.Dtl.Data.Bskt[1:52,]

#Created a dataframe with total sales at product level
Tot.Sls.Low.Bskt <- as.data.frame(colSums(Low.Dtl.Data.Bskt[,c(1:395)])) 
names(Tot.Sls.Low.Bskt)[1] <- "Yr.Sls"

summary(Tot.Sls.Low.Bskt)
##      Yr.Sls      
##  Min.   :  2.00  
##  1st Qu.:  9.00  
##  Median : 21.00  
##  Mean   : 55.64  
##  3rd Qu.:110.50  
##  Max.   :198.00
hist(Tot.Sls.Low.Bskt$Yr.Sls,main = "No of Product vs Sales Distribution on Low Category", xlab = "Sale")

boxplot(Tot.Sls.Low.Bskt$Yr.Sls, main = "Plot", names = c("Low"))

#Mid Product Group Analysis
Mid.Prdt.List<- Tot.Sls.Bkt %>% select(Prdt,Mid) %>% filter(Mid==1)
head(Mid.Prdt.List)
##   Prdt Mid
## 1 P115   1
## 2 P528   1
## 3 P527   1
## 4 P488   1
## 5 P542   1
## 6 P106   1
Mid.Prdt.List$Prdt
##   [1] P115 P528 P527 P488 P542 P106 P493 P492 P541 P522 P9   P543 P555 P26 
##  [15] P198 P521 P547 P632 P634 P209 P334 P524 P165 P627 P314 P518 P118 P166
##  [29] P397 P1   P197 P485 P560 P71  P144 P266 P633 P264 P65  P109 P22  P114
##  [43] P149 P153 P267 P625 P116 P294 P99  P309 P539 P629 P564 P147 P285 P515
##  [57] P550 P413 P551 P152 P299 P319 P32  P160 P333 P532 P324 P404 P534 P13 
##  [71] P145 P74  P496 P59  P20  P164 P122 P626 P81  P635 P21  P436 P624 P110
##  [85] P121 P332 P631 P50  P91  P94  P429 P499 P508 P93  P3   P552 P8   P563
##  [99] P630 P162 P171 P82  P31  P68  P565 P5   P146 P628 P125 P154 P490 P4  
## [113] P157 P304 P103 P432 P674 P510 P500 P431 P437 P203 P586 P702 P207 P509
## [127] P791 P596 P614 P368 P392 P571 P745 P806 P814 P359 P501 P305 P531 P616
## [141] P799 P331 P124 P111 P53  P77  P310 P497 P295 P329 P489 P675 P161 P484
## [155] P307 P117 P195 P311 P317 P126 P300 P151 P6   P313 P562 P637 P296 P316
## [169] P320 P302 P321 P23  P325 P7   P159 P301 P306 P312 P326 P433 P323 P98 
## [183] P328 P330 P2   P308 P315 P104 P768 P150 P298 P155 P163 P297 P369 P12 
## [197] P561 P327 P553 P148 P337 P303
## 811 Levels: P1 P10 P100 P101 P102 P103 P104 P105 P106 P107 P108 ... P99
Mid.Dtl.Data<- Data.Copy %>% filter(Product_Code %in% c("P115","P528","P527","P488","P542","P106","P493","P492","P541","P522","P9","P543","P555","P26","P198","P521","P547","P632","P634","P209","P334","P524","P165","P627","P314","P518","P118","P166","P397","P1","P197","P485","P560","P71","P144","P266","P633","P264","P65","P109","P22","P114","P149","P153","P267","P625","P116","P294","P99","P309","P539","P629","P564","P147","P285","P515","P550","P413","P551","P152","P299","P319","P32","P160","P333","P532","P324","P404","P534","P13","P145","P74","P496","P59","P20","P164","P122","P626","P81","P635","P21","P436","P624","P110","P121","P332","P631","P50","P91","P94","P429","P499","P508","P93","P3","P552","P8","P563","P630","P162","P171","P82","P31","P68","P565","P5","P146","P628","P125","P154","P490","P4","P157","P304","P103","P432","P674","P510","P500","P431","P437","P203","P586","P702","P207","P509","P791","P596","P614","P368","P392","P571","P745","P806","P814","P359","P501","P305","P531","P616","P799","P331","P124","P111","P53","P77","P310","P497","P295","P329","P489","P675","P161","P484","P307","P117","P195","P311","P317","P126","P300","P151","P6","P313","P562","P637","P296","P316","P320","P302","P321","P23","P325","P7","P159","P301","P306","P312","P326","P433","P323","P98","P328","P330","P2","P308","P315","P104","P768","P150","P298","P155","P163","P297","P369","P12","P561","P327","P553","P148","P337","P303")
)
head(Mid.Dtl.Data)
##   Product_Code W0 W1 W2 W3 W4 W5 W6 W7 W8 W9 W10 W11 W12 W13 W14 W15 W16
## 1           P1 11 12 10  8 13 12 14 21  6 14  11  14  16   9   9   9  14
## 2           P2  7  6  3  2  7  1  6  3  3  3   2   2   6   2   0   6   2
## 3           P3  7 11  8  9 10  8  7 13 12  6  14   9   4   7  12   8   7
## 4           P4 12  8 13  5  9  6  9 13 13 11   8   4   5   4  15   7  11
## 5           P5  8  5 13 11  6  7  9 14  9  9  11  18   8   4  13   8  10
## 6           P6  3  3  2  7  6  3  8  6  6  3   1   1   5   4   3   5   3
##   W17 W18 W19 W20 W21 W22 W23 W24 W25 W26 W27 W28 W29 W30 W31 W32 W33 W34
## 1   9   3  12   5  11   7  12   5   9   7  10   5  11   7  10  12   6   5
## 2   7   7   9   4   7   2   4   5   3   5   8   5   5   3   1   3   2   3
## 3  11  10   7   7  13  11   8  10   8  14   5   3  13  11   9   7   8   7
## 4   9  15   4   6   7  11   7   9   6  10  10   2   6   7   2   5  12   5
## 5  15   6  13  11   6  10   9   8  12   8   9  13   3   5   3   5   5   9
## 6   5  10   8   4   9   7   5   4   2   1   3   2   4   0   3   2  11   2
##   W35 W36 W37 W38 W39 W40 W41 W42 W43 W44 W45 W46 W47 W48 W49 W50 W51 MIN
## 1  14  10   9  12  17   7  11   4   7   8  10  12   3   7   6   5  10   3
## 2  10   5   2   7   3   2   5   2   4   5   1   1   4   5   1   6   0   0
## 3   9   6  12  12   9   3   5   6  14   5   5   7   8  14   8   8   7   3
## 4  19   8   6   8   8  12   6   9  10   3   4   6   8  14   8   7   8   2
## 5   7   4   8   8   5   5   8   7  11   7  12   6   6   5  11   8   9   3
## 6   1   4   4   3   2   5   4   4   2   4   3   6   5   3   3  10   6   0
##   MAX Normalized.0 Normalized.1 Normalized.2 Normalized.3 Normalized.4
## 1  21         0.44         0.50         0.39         0.28         0.56
## 2  10         0.70         0.60         0.30         0.20         0.70
## 3  14         0.36         0.73         0.45         0.55         0.64
## 4  19         0.59         0.35         0.65         0.18         0.41
## 5  18         0.33         0.13         0.67         0.53         0.20
## 6  11         0.27         0.27         0.18         0.64         0.55
##   Normalized.5 Normalized.6 Normalized.7 Normalized.8 Normalized.9
## 1         0.50         0.61         1.00         0.17         0.61
## 2         0.10         0.60         0.30         0.30         0.30
## 3         0.45         0.36         0.91         0.82         0.27
## 4         0.24         0.41         0.65         0.65         0.53
## 5         0.27         0.40         0.73         0.40         0.40
## 6         0.27         0.73         0.55         0.55         0.27
##   Normalized.10 Normalized.11 Normalized.12 Normalized.13 Normalized.14
## 1          0.44          0.61          0.72          0.33          0.33
## 2          0.20          0.20          0.60          0.20          0.00
## 3          1.00          0.55          0.09          0.36          0.82
## 4          0.35          0.12          0.18          0.12          0.76
## 5          0.53          1.00          0.33          0.07          0.67
## 6          0.09          0.09          0.45          0.36          0.27
##   Normalized.15 Normalized.16 Normalized.17 Normalized.18 Normalized.19
## 1          0.33          0.61          0.33          0.00          0.50
## 2          0.60          0.20          0.70          0.70          0.90
## 3          0.45          0.36          0.73          0.64          0.36
## 4          0.29          0.53          0.41          0.76          0.12
## 5          0.33          0.47          0.80          0.20          0.67
## 6          0.45          0.27          0.45          0.91          0.73
##   Normalized.20 Normalized.21 Normalized.22 Normalized.23 Normalized.24
## 1          0.11          0.44          0.22          0.50          0.11
## 2          0.40          0.70          0.20          0.40          0.50
## 3          0.36          0.91          0.73          0.45          0.64
## 4          0.24          0.29          0.53          0.29          0.41
## 5          0.53          0.20          0.47          0.40          0.33
## 6          0.36          0.82          0.64          0.45          0.36
##   Normalized.25 Normalized.26 Normalized.27 Normalized.28 Normalized.29
## 1          0.33          0.22          0.39          0.11          0.44
## 2          0.30          0.50          0.80          0.50          0.50
## 3          0.45          1.00          0.18          0.00          0.91
## 4          0.24          0.47          0.47          0.00          0.24
## 5          0.60          0.33          0.40          0.67          0.00
## 6          0.18          0.09          0.27          0.18          0.36
##   Normalized.30 Normalized.31 Normalized.32 Normalized.33 Normalized.34
## 1          0.22          0.39          0.50          0.17          0.11
## 2          0.30          0.10          0.30          0.20          0.30
## 3          0.73          0.55          0.36          0.45          0.36
## 4          0.29          0.00          0.18          0.59          0.18
## 5          0.13          0.00          0.13          0.13          0.40
## 6          0.00          0.27          0.18          1.00          0.18
##   Normalized.35 Normalized.36 Normalized.37 Normalized.38 Normalized.39
## 1          0.61          0.39          0.33          0.50          0.78
## 2          1.00          0.50          0.20          0.70          0.30
## 3          0.55          0.27          0.82          0.82          0.55
## 4          1.00          0.35          0.24          0.35          0.35
## 5          0.27          0.07          0.33          0.33          0.13
## 6          0.09          0.36          0.36          0.27          0.18
##   Normalized.40 Normalized.41 Normalized.42 Normalized.43 Normalized.44
## 1          0.22          0.44          0.06          0.22          0.28
## 2          0.20          0.50          0.20          0.40          0.50
## 3          0.00          0.18          0.27          1.00          0.18
## 4          0.59          0.24          0.41          0.47          0.06
## 5          0.13          0.33          0.27          0.53          0.27
## 6          0.45          0.36          0.36          0.18          0.36
##   Normalized.45 Normalized.46 Normalized.47 Normalized.48 Normalized.49
## 1          0.39          0.50          0.00          0.22          0.17
## 2          0.10          0.10          0.40          0.50          0.10
## 3          0.18          0.36          0.45          1.00          0.45
## 4          0.12          0.24          0.35          0.71          0.35
## 5          0.60          0.20          0.20          0.13          0.53
## 6          0.27          0.55          0.45          0.27          0.27
##   Normalized.50 Normalized.51
## 1          0.11          0.39
## 2          0.60          0.00
## 3          0.45          0.36
## 4          0.29          0.35
## 5          0.33          0.40
## 6          0.91          0.55
Mid_Prod_Name <- Mid.Dtl.Data$Product_Code
rownames(Mid.Dtl.Data) <- Mid.Dtl.Data$Product_Code
Mid.Dtl.Data$Product_Code<- NULL
Mid.Dtl.Data.Bskt<- as.data.frame(t(as.matrix(Mid.Dtl.Data)))
Mid.Dtl.Data.Bskt <- Mid.Dtl.Data.Bskt[1:52,]

#Created a dataframe with total sales at product level
Tot.Sls.Mid.Bskt <- as.data.frame(colSums(Mid.Dtl.Data.Bskt[,c(1:202)])) 
names(Tot.Sls.Mid.Bskt)[1] <- "Yr.Sls"
Tot.Sls.By.Prdt <- cbind(Prdt,Tot.Sls.By.Prdt)
rownames(Tot.Sls.By.Prdt) <- NULL
summary(Tot.Sls.Mid.Bskt)
##      Yr.Sls     
##  Min.   :200.0  
##  1st Qu.:229.2  
##  Median :446.0  
##  Mean   :378.8  
##  3rd Qu.:482.0  
##  Max.   :571.0
hist(Tot.Sls.Mid.Bskt$Yr.Sls, main = "No of Product vs Sales Distribution on Mid Category", xlab = "Sale")

boxplot(Tot.Sls.Mid.Bskt$Yr.Sls, main = "Plot", names = c("Mid"))

#Create timeseries of top 5 products
P409.df<-prod.wkly.sls %>% select(P409)
P409.ts <- ts(P409.df, frequency=52)

P34.df<-prod.wkly.sls %>% select(P34)
P34.ts <- ts(P34.df, frequency=52)

P178.df<-prod.wkly.sls %>% select(P178)
P178.ts <- ts(P178.df, frequency=52)

P135.df<-prod.wkly.sls %>% select(P135)
P135.ts <- ts(P135.df, frequency=52)

P43.df<-prod.wkly.sls %>% select(P43)
P43.ts <- ts(P43.df, frequency=52)
#Forecasting of P409
autoplot(P409.ts)+ ggtitle("P409")+ xlab("Week")+ylab("Sales")

P409_fit_ets <- ets(P409.ts)
summary(P409_fit_ets)
## ETS(M,N,N) 
## 
## Call:
##  ets(y = P409.ts) 
## 
##   Smoothing parameters:
##     alpha = 0.4844 
## 
##   Initial states:
##     l = 40.3168 
## 
##   sigma:  0.2375
## 
##      AIC     AICc      BIC 
## 446.3975 446.8975 452.2512 
## 
## Training set error measures:
##                     ME     RMSE      MAE      MPE     MAPE MASE       ACF1
## Training set 0.8212682 10.57843 7.725092 -3.44772 19.74376  NaN 0.04469462
checkresiduals(P409_fit_ets)

## 
##  Ljung-Box test
## 
## data:  Residuals from ETS(M,N,N)
## Q* = 11.714, df = 8.4, p-value = 0.1894
## 
## Model df: 2.   Total lags used: 10.4
autoplot(forecast(P409_fit_ets, h = 4)) + xlab("Week") + ylab("Sales") + ggtitle("P409 Forecast using ETS Method")

summary(ur.kpss(P409.ts))
## 
## ####################### 
## # KPSS Unit Root Test # 
## ####################### 
## 
## Test is of type: mu with 3 lags. 
## 
## Value of test-statistic is: 0.115 
## 
## Critical value for a significance level of: 
##                 10pct  5pct 2.5pct  1pct
## critical values 0.347 0.463  0.574 0.739
p1 <- ggAcf(P409.ts)
p2 <- ggPacf(P409.ts)
grid.arrange(p1, p2, ncol = 2)

p409_fit_arima <- auto.arima(P409.ts, seasonal = FALSE)
summary(p409_fit_arima)
## Series: P409.ts 
## ARIMA(1,0,0) with non-zero mean 
## 
## Coefficients:
##          ar1     mean
##       0.5160  43.2755
## s.e.  0.1267   2.9042
## 
## sigma^2 estimated as 110.2:  log likelihood=-195.17
## AIC=396.34   AICc=396.84   BIC=402.2
## 
## Training set error measures:
##                      ME     RMSE      MAE       MPE     MAPE MASE
## Training set 0.01617023 10.29233 7.781377 -6.132657 19.99894  NaN
##                     ACF1
## Training set -0.04291878
checkresiduals(p409_fit_arima)

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(1,0,0) with non-zero mean
## Q* = 13.541, df = 8.4, p-value = 0.1113
## 
## Model df: 2.   Total lags used: 10.4
autoplot(forecast(p409_fit_arima, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P409 Forecast using ARIMA")

forecast(p409_fit_arima,h=4)
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 2.000000       58.61293 45.16157 72.06430 38.04084 79.18502
## 2.019231       51.18941 36.05295 66.32588 28.04018 74.33865
## 2.038462       47.35899 31.80462 62.91336 23.57063 71.14735
## 2.057692       45.38254 29.71879 61.04630 21.42690 69.33819
p1 <- autoplot(P409.ts) + autolayer(meanf(P409.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P409 Forecast using Average Method")
p2 <- autoplot(P409.ts) + autolayer(naive(P409.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P409 Forecast using Naive Method")
p3 <- autoplot(P409.ts) + autolayer(rwf(P409.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P409Forecast using Drift Method")
grid.arrange(p1, p2, p3, ncol = 3)

#Forecasting of P34
autoplot(P34.ts)+ ggtitle("P34")+ xlab("Week")+ylab("Sales")

P34_fit_ets <- ets(P34.ts)
summary(P34_fit_ets)
## ETS(M,N,N) 
## 
## Call:
##  ets(y = P34.ts) 
## 
##   Smoothing parameters:
##     alpha = 0.0923 
## 
##   Initial states:
##     l = 41.2495 
## 
##   sigma:  0.2045
## 
##      AIC     AICc      BIC 
## 423.1565 423.6565 429.0103 
## 
## Training set error measures:
##                     ME     RMSE      MAE       MPE     MAPE MASE
## Training set -1.100599 7.789164 5.909122 -7.572166 17.78021  NaN
##                    ACF1
## Training set -0.1352629
checkresiduals(P34_fit_ets)

## 
##  Ljung-Box test
## 
## data:  Residuals from ETS(M,N,N)
## Q* = 19.527, df = 8.4, p-value = 0.01536
## 
## Model df: 2.   Total lags used: 10.4
autoplot(forecast(P34_fit_ets, h = 4)) + xlab("Week") + ylab("Sales") + ggtitle("P34 Forecast using ETS Method")

summary(ur.kpss(P34.ts))
## 
## ####################### 
## # KPSS Unit Root Test # 
## ####################### 
## 
## Test is of type: mu with 3 lags. 
## 
## Value of test-statistic is: 0.5382 
## 
## Critical value for a significance level of: 
##                 10pct  5pct 2.5pct  1pct
## critical values 0.347 0.463  0.574 0.739
p1 <- ggAcf(P34.ts)
p2 <- ggPacf(P34.ts)
grid.arrange(p1, p2, ncol = 2)

p34_fit_arima <- auto.arima(P34.ts, seasonal = FALSE)
summary(p34_fit_arima)
## Series: P34.ts 
## ARIMA(3,1,2) 
## 
## Coefficients:
##           ar1      ar2      ar3      ma1      ma2
##       -0.9397  -0.5901  -0.2055  -0.0596  -0.5850
## s.e.   0.3688   0.2525   0.2577   0.3408   0.2344
## 
## sigma^2 estimated as 55.82:  log likelihood=-173.4
## AIC=358.8   AICc=360.71   BIC=370.39
## 
## Training set error measures:
##                     ME    RMSE      MAE       MPE     MAPE MASE
## Training set -0.582173 7.02675 5.616037 -5.177022 16.33428  NaN
##                      ACF1
## Training set -0.004282835
checkresiduals(p34_fit_arima)

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(3,1,2)
## Q* = 7.9037, df = 5.4, p-value = 0.1932
## 
## Model df: 5.   Total lags used: 10.4
autoplot(forecast(p34_fit_arima, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P34 Forecast using ARIMA")

forecast(p34_fit_arima,h=4)
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 2.000000       38.14782 28.57338 47.72226 23.50498 52.79066
## 2.019231       41.42214 31.84769 50.99658 26.77929 56.06498
## 2.038462       34.25893 24.42297 44.09490 19.21612 49.30174
## 2.057692       36.56186 26.10526 47.01846 20.56987 52.55385
p1 <- autoplot(P34.ts) + autolayer(meanf(P34.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P34 Forecast using Average Method")
p2 <- autoplot(P34.ts) + autolayer(naive(P34.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P34 Forecast using Naive Method")
p3 <- autoplot(P34.ts) + autolayer(rwf(P34.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P34Forecast using Drift Method")
grid.arrange(p1, p2, p3, ncol = 3)

#Forecasting of P178
autoplot(P178.ts)+ ggtitle("P178")+ xlab("Week")+ylab("Sales")

P178_fit_ets <- ets(P178.ts)
summary(P178_fit_ets)
## ETS(A,N,N) 
## 
## Call:
##  ets(y = P178.ts) 
## 
##   Smoothing parameters:
##     alpha = 0.2736 
## 
##   Initial states:
##     l = 37.4499 
## 
##   sigma:  7.4224
## 
##      AIC     AICc      BIC 
## 417.8930 418.3930 423.7467 
## 
## Training set error measures:
##                      ME     RMSE      MAE       MPE     MAPE MASE
## Training set -0.4285944 7.278231 5.643992 -5.073001 16.56116  NaN
##                     ACF1
## Training set -0.01996414
checkresiduals(P178_fit_ets)

## 
##  Ljung-Box test
## 
## data:  Residuals from ETS(A,N,N)
## Q* = 4.4406, df = 8.4, p-value = 0.8438
## 
## Model df: 2.   Total lags used: 10.4
autoplot(forecast(P178_fit_ets, h = 4)) + xlab("Week") + ylab("Sales") + ggtitle("P178 Forecast using ETS Method")

summary(ur.kpss(diff(P178.ts)))
## 
## ####################### 
## # KPSS Unit Root Test # 
## ####################### 
## 
## Test is of type: mu with 3 lags. 
## 
## Value of test-statistic is: 0.0901 
## 
## Critical value for a significance level of: 
##                 10pct  5pct 2.5pct  1pct
## critical values 0.347 0.463  0.574 0.739
p1 <- ggAcf(diff(P178.ts))
p2 <- ggPacf(diff(P178.ts))
grid.arrange(p1, p2, ncol = 2)

p178_fit_arima <- auto.arima(diff(P178.ts), seasonal = FALSE)
summary(p178_fit_arima)
## Series: diff(P178.ts) 
## ARIMA(0,0,1) with zero mean 
## 
## Coefficients:
##           ma1
##       -0.7081
## s.e.   0.1116
## 
## sigma^2 estimated as 55.12:  log likelihood=-174.45
## AIC=352.9   AICc=353.15   BIC=356.77
## 
## Training set error measures:
##                      ME     RMSE      MAE  MPE MAPE MASE        ACF1
## Training set -0.3036805 7.351146 5.692531 -Inf  Inf  NaN -0.03417743
checkresiduals(p178_fit_arima)

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(0,0,1) with zero mean
## Q* = 4.3884, df = 9.2, p-value = 0.8943
## 
## Model df: 1.   Total lags used: 10.2
autoplot(forecast(p178_fit_arima, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P178 Forecast using ARIMA")

forecast(p178_fit_arima,h=4)
##          Point Forecast      Lo 80    Hi 80      Lo 95    Hi 95
## 2.000000          5.084  -4.430615 14.59861  -9.467348 19.63535
## 2.019231          0.000 -11.658634 11.65863 -17.830343 17.83034
## 2.038462          0.000 -11.658634 11.65863 -17.830343 17.83034
## 2.057692          0.000 -11.658634 11.65863 -17.830343 17.83034
p1 <- autoplot(P178.ts) + autolayer(meanf(P178.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P178 Forecast using Average Method")
p2 <- autoplot(P178.ts) + autolayer(naive(P178.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P178 Forecast using Naive Method")
p3 <- autoplot(P178.ts) + autolayer(rwf(P178.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P178Forecast using Drift Method")
grid.arrange(p1, p2, p3, ncol = 3)

#Forecasting of P135
autoplot(P135.ts)+ ggtitle("P135")+ xlab("Week")+ylab("Sales")

P135_fit_ets <- ets(P135.ts)
summary(P135_fit_ets)
## ETS(A,N,N) 
## 
## Call:
##  ets(y = P135.ts) 
## 
##   Smoothing parameters:
##     alpha = 0.2337 
## 
##   Initial states:
##     l = 37.6663 
## 
##   sigma:  7.5356
## 
##      AIC     AICc      BIC 
## 419.4677 419.9677 425.3215 
## 
## Training set error measures:
##                      ME     RMSE      MAE       MPE    MAPE MASE
## Training set -0.6751885 7.389274 5.741731 -6.331545 17.5548  NaN
##                     ACF1
## Training set -0.03564441
checkresiduals(P135_fit_ets)

## 
##  Ljung-Box test
## 
## data:  Residuals from ETS(A,N,N)
## Q* = 8.5352, df = 8.4, p-value = 0.4223
## 
## Model df: 2.   Total lags used: 10.4
autoplot(forecast(P135_fit_ets, h = 4)) + xlab("Week") + ylab("Sales") + ggtitle("P135 Forecast using ETS Method")

summary(ur.kpss(diff(P135.ts)))
## 
## ####################### 
## # KPSS Unit Root Test # 
## ####################### 
## 
## Test is of type: mu with 3 lags. 
## 
## Value of test-statistic is: 0.1163 
## 
## Critical value for a significance level of: 
##                 10pct  5pct 2.5pct  1pct
## critical values 0.347 0.463  0.574 0.739
p1 <- ggAcf(diff(P135.ts))
p2 <- ggPacf(diff(P135.ts))
grid.arrange(p1, p2, ncol = 2)

P135_fit_arima <- auto.arima(diff(P135.ts), seasonal = FALSE)
summary(P135_fit_arima)
## Series: diff(P135.ts) 
## ARIMA(0,0,1) with zero mean 
## 
## Coefficients:
##           ma1
##       -0.7394
## s.e.   0.1240
## 
## sigma^2 estimated as 56.83:  log likelihood=-175.28
## AIC=354.56   AICc=354.81   BIC=358.42
## 
## Training set error measures:
##                      ME    RMSE      MAE MPE MAPE MASE        ACF1
## Training set -0.5964362 7.46462 5.886218 NaN  Inf  NaN -0.05414681
checkresiduals(P135_fit_arima)

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(0,0,1) with zero mean
## Q* = 9.1106, df = 9.2, p-value = 0.4462
## 
## Model df: 1.   Total lags used: 10.2
autoplot(forecast(P135_fit_arima, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P135 Forecast using ARIMA")

forecast(P135_fit_arima,h=4)
##          Point Forecast      Lo 80    Hi 80      Lo 95    Hi 95
## 2.000000       12.78969   3.128202 22.45117  -1.986279 27.56565
## 2.019231        0.00000 -12.015849 12.01585 -18.376655 18.37665
## 2.038462        0.00000 -12.015849 12.01585 -18.376655 18.37665
## 2.057692        0.00000 -12.015849 12.01585 -18.376655 18.37665
p1 <- autoplot(P135.ts) + autolayer(meanf(P135.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P135 Forecast using Average Method")
p2 <- autoplot(P135.ts) + autolayer(naive(P135.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P135 Forecast using Naive Method")
p3 <- autoplot(P135.ts) + autolayer(rwf(P135.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P135Forecast using Drift Method")
grid.arrange(p1, p2, p3, ncol = 3)

#Forecasting of P43
autoplot(P43.ts)+ ggtitle("P43")+ xlab("Week")+ylab("Sales")

P43_fit_ets <- ets(P43.ts)
summary(P43_fit_ets)
## ETS(M,N,N) 
## 
## Call:
##  ets(y = P43.ts) 
## 
##   Smoothing parameters:
##     alpha = 0.3196 
## 
##   Initial states:
##     l = 38.5878 
## 
##   sigma:  0.2224
## 
##      AIC     AICc      BIC 
## 428.1162 428.6162 433.9699 
## 
## Training set error measures:
##                      ME    RMSE      MAE       MPE     MAPE MASE
## Training set -0.4379003 8.04433 6.976893 -5.388537 20.01099  NaN
##                    ACF1
## Training set 0.02390699
checkresiduals(P43_fit_ets)

## 
##  Ljung-Box test
## 
## data:  Residuals from ETS(M,N,N)
## Q* = 11.824, df = 8.4, p-value = 0.1836
## 
## Model df: 2.   Total lags used: 10.4
autoplot(forecast(P43_fit_ets, h = 4)) + xlab("Week") + ylab("Sales") + ggtitle("P43 Forecast using ETS Method")

summary(ur.kpss(diff(P43.ts)))
## 
## ####################### 
## # KPSS Unit Root Test # 
## ####################### 
## 
## Test is of type: mu with 3 lags. 
## 
## Value of test-statistic is: 0.1014 
## 
## Critical value for a significance level of: 
##                 10pct  5pct 2.5pct  1pct
## critical values 0.347 0.463  0.574 0.739
p1 <- ggAcf(diff(P43.ts))
p2 <- ggPacf(diff(P43.ts))
grid.arrange(p1, p2, ncol = 2)

p43_fit_arima <- auto.arima(diff(P43.ts), seasonal = FALSE)
summary(p43_fit_arima)
## Series: diff(P43.ts) 
## ARIMA(1,0,1) with zero mean 
## 
## Coefficients:
##          ar1      ma1
##       0.0796  -0.7157
## s.e.  0.2426   0.1910
## 
## sigma^2 estimated as 68.48:  log likelihood=-179.42
## AIC=364.85   AICc=365.36   BIC=370.64
## 
## Training set error measures:
##                       ME     RMSE      MAE MPE MAPE MASE       ACF1
## Training set -0.08860345 8.111088 6.966843 Inf  Inf  NaN 0.01719383
checkresiduals(p43_fit_arima)

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(1,0,1) with zero mean
## Q* = 6.2418, df = 8.2, p-value = 0.6404
## 
## Model df: 2.   Total lags used: 10.2
autoplot(forecast(p43_fit_arima, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P43 Forecast using ARIMA")

forecast(p43_fit_arima,h=4)
##          Point Forecast      Lo 80    Hi 80     Lo 95    Hi 95
## 2.000000     4.27327683  -6.331517 14.87807 -11.94536 20.49191
## 2.019231     0.34017058 -12.228501 12.90884 -18.88195 19.56230
## 2.038462     0.02707899 -12.553060 12.60722 -19.21258 19.26674
## 2.057692     0.00215560 -12.578056 12.58237 -19.23762 19.24193
p1 <- autoplot(P43.ts) + autolayer(meanf(P43.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P43 Forecast using Average Method")
p2 <- autoplot(P43.ts) + autolayer(naive(P43.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P43 Forecast using Naive Method")
p3 <- autoplot(P43.ts) + autolayer(rwf(P43.ts, h = 4)) + xlab("Week") + ylab("Number of Transactions") + ggtitle("P43Forecast using Drift Method")
grid.arrange(p1, p2, p3, ncol = 3)