Load any libraries here

#install.packages("tidyverse")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
#install.packages("latexpdf")
library(latexpdf)

1 - Load data

df <- read.csv("store_3.csv")

2 - Familiarization with the data

summary(df)
##      store           city              region            province        
##  Min.   :  105   Length:771         Length:771         Length:771        
##  1st Qu.: 6226   Class :character   Class :character   Class :character  
##  Median :34438   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :34226                                                           
##  3rd Qu.:59663                                                           
##  Max.   :98788                                                           
##                                                                          
##       size          revenue              units              cost         
##  Min.   : 276.0   Length:771         Min.   :  42.65   Min.   :   41.12  
##  1st Qu.: 671.8   Class :character   1st Qu.: 911.85   1st Qu.: 1229.12  
##  Median : 792.5   Mode  :character   Median :1351.25   Median : 1843.41  
##  Mean   : 755.5                      Mean   :1559.78   Mean   : 2180.51  
##  3rd Qu.: 893.0                      3rd Qu.:1941.60   3rd Qu.: 2689.76  
##  Max.   :1163.0                      Max.   :9715.83   Max.   :14228.89  
##  NA's   :15                                                              
##   gross_profit       promo_units      energy_units    regularBars_units
##  Min.   :   36.36   Min.   :  17.5   Min.   :   4.1   Min.   :  5.10   
##  1st Qu.:  771.74   1st Qu.: 344.4   1st Qu.: 142.7   1st Qu.: 75.67   
##  Median : 1150.93   Median : 499.3   Median : 215.6   Median :110.65   
##  Mean   : 1388.03   Mean   : 567.0   Mean   : 253.0   Mean   :123.95   
##  3rd Qu.: 1702.92   3rd Qu.: 730.5   3rd Qu.: 317.1   3rd Qu.:154.84   
##  Max.   :10457.82   Max.   :3116.5   Max.   :1576.3   Max.   :681.56   
##                                                                        
##    gum_units      bagpegCandy_units isotonics_units  singleServePotato_units
##  Min.   :  1.88   Min.   :  0.00    Min.   :  3.98   Min.   :  1.75         
##  1st Qu.: 53.49   1st Qu.: 24.43    1st Qu.: 57.79   1st Qu.: 29.51         
##  Median : 77.88   Median : 41.65    Median : 84.48   Median : 44.92         
##  Mean   : 85.53   Mean   : 50.33    Mean   : 98.76   Mean   : 56.34         
##  3rd Qu.:110.11   3rd Qu.: 63.72    3rd Qu.:124.16   3rd Qu.: 67.84         
##  Max.   :318.69   Max.   :381.96    Max.   :562.46   Max.   :439.06         
##                                                                             
##  takeHomePotato_units kingBars_units   flatWater_units   psd591Ml_units  
##  Min.   :  0.00       Min.   :  0.00   Min.   :  11.96   Min.   :  0.00  
##  1st Qu.: 15.69       1st Qu.: 33.89   1st Qu.:  82.33   1st Qu.: 31.28  
##  Median : 28.85       Median : 49.87   Median : 128.98   Median : 48.25  
##  Mean   : 38.05       Mean   : 58.68   Mean   : 158.03   Mean   : 60.57  
##  3rd Qu.: 49.31       3rd Qu.: 73.33   3rd Qu.: 190.32   3rd Qu.: 74.95  
##  Max.   :360.19       Max.   :471.19   Max.   :1424.27   Max.   :390.38  
## 
str(df)
## 'data.frame':    771 obs. of  20 variables:
##  $ store                  : int  105 117 122 123 182 183 186 194 227 233 ...
##  $ city                   : chr  "BROCKVILLE" "BURLINGTON" "BURLINGTON" "BURLINGTON" ...
##  $ region                 : chr  "ONTARIO" "ONTARIO" "ONTARIO" "ONTARIO" ...
##  $ province               : chr  "ON" "ON" "ON" "ON" ...
##  $ size                   : int  496 875 691 763 784 NA 966 710 973 967 ...
##  $ revenue                : chr  "984.7" "2629.32" "2786.73" "2834.49" ...
##  $ units                  : num  470 1131 1229 1258 1950 ...
##  $ cost                   : num  591 1622 1709 1720 2486 ...
##  $ gross_profit           : num  394 1008 1077 1115 1633 ...
##  $ promo_units            : num  210 401 450 477 665 ...
##  $ energy_units           : num  72.1 192.8 240.5 194.2 199.7 ...
##  $ regularBars_units      : num  38.6 75 93.7 99.4 175.5 ...
##  $ gum_units              : num  29.3 55.9 64.3 73.2 145.8 ...
##  $ bagpegCandy_units      : num  13.4 42.1 29.9 54.1 68.1 ...
##  $ isotonics_units        : num  20.7 87.6 105.7 118.2 109.3 ...
##  $ singleServePotato_units: num  18.6 36.4 48 39.7 85.7 ...
##  $ takeHomePotato_units   : num  7.71 33.46 19.9 22.1 42.33 ...
##  $ kingBars_units         : num  17.9 47.4 45.2 45.3 79.8 ...
##  $ flatWater_units        : num  56.5 98.4 130.3 132.8 204.1 ...
##  $ psd591Ml_units         : num  39.7 38.7 47.3 39.9 50.3 ...
head(df)
##   store       city  region province size revenue   units    cost gross_profit
## 1   105 BROCKVILLE ONTARIO       ON  496   984.7  470.46  590.73       393.97
## 2   117 BURLINGTON ONTARIO       ON  875 2629.32 1131.38 1621.58      1007.74
## 3   122 BURLINGTON ONTARIO       ON  691 2786.73 1229.46 1709.45      1077.27
## 4   123 BURLINGTON ONTARIO       ON  763 2834.49 1257.63 1719.61      1114.88
## 5   182  DON MILLS ONTARIO       ON  784 4118.36 1949.50 2485.83      1632.53
## 6   183  DON MILLS ONTARIO       ON   NA  374.83  186.54  227.36       147.47
##   promo_units energy_units regularBars_units gum_units bagpegCandy_units
## 1      210.23        72.13             38.63     29.29             13.38
## 2      401.46       192.77             75.04     55.85             42.15
## 3      450.04       240.48             93.73     64.27             29.85
## 4      476.83       194.21             99.44     73.25             54.15
## 5      664.71       199.73            175.48    145.81             68.06
## 6       79.23        34.23             17.06     11.71              3.73
##   isotonics_units singleServePotato_units takeHomePotato_units kingBars_units
## 1           20.69                   18.60                 7.71          17.87
## 2           87.62                   36.44                33.46          47.44
## 3          105.65                   47.96                19.90          45.21
## 4          118.19                   39.67                22.10          45.33
## 5          109.35                   85.71                42.33          79.81
## 6            9.29                    8.48                 0.00          11.88
##   flatWater_units psd591Ml_units
## 1           56.54          39.71
## 2           98.42          38.73
## 3          130.27          47.31
## 4          132.77          39.87
## 5          204.06          50.29
## 6           25.31           2.69
tail(df)
##     store        city region province size revenue   units    cost gross_profit
## 766 94285     UNKNOWN QUEBEC  UNKNOWN  343 1121.61  534.63  678.85       442.75
## 767 95198       SOOKE   WEST       BC  707 2910.59 1305.92 1777.54      1133.05
## 768 95342 MAPLE RIDGE   WEST       BC  711 1786.36  789.38 1088.62       697.74
## 769 95849   VANCOUVER   WEST       BC  444 1497.23  703.52  902.25       594.97
## 770 97250    WINNIPEG   WEST       MB  723 2093.18  928.54 1325.07       768.11
## 771 98788   VANCOUVER   WEST       BC  885 3753.52 1644.13 2245.66      1507.87
##     promo_units energy_units regularBars_units gum_units bagpegCandy_units
## 766      168.93        90.44             43.00     40.19              0.74
## 767      401.46       151.17            122.63     51.46             51.12
## 768      352.19       130.87             70.83     46.50             22.69
## 769      256.42        81.98             66.71     29.29             18.42
## 770      438.96       113.96             72.38     38.17             31.48
## 771      451.71       207.17            118.27     86.92             52.98
##     isotonics_units singleServePotato_units takeHomePotato_units kingBars_units
## 766           34.22                   22.07                 3.15          32.93
## 767           85.21                   46.25                30.15          74.52
## 768           52.69                   19.02                14.58          22.52
## 769           72.29                   24.83                 7.60          26.60
## 770           68.37                   30.00                27.44          38.67
## 771          105.87                   68.38                38.83          47.79
##     flatWater_units psd591Ml_units
## 766           49.00          18.00
## 767          110.79          43.27
## 768           73.54          32.15
## 769           86.15          24.88
## 770           93.10          59.35
## 771          195.31          37.75
slice_sample(df, n=5)
##   store          city  region province size revenue   units    cost
## 1   655 RICHMOND HILL ONTARIO       ON  758 2342.59 1020.90 1409.13
## 2 36531      EDMONTON    WEST       AB   NA  733.04  341.25  438.89
## 3 14082     LONGUEUIL  QUEBEC       QC  875  2792.7 1215.62 1774.36
## 4 13303       MIRABEL  QUEBEC       QC  877 6314.35 2657.15 3795.51
## 5   398        LONDON ONTARIO       ON  609 1372.67  625.35  857.48
##   gross_profit promo_units energy_units regularBars_units gum_units
## 1       933.46      297.88       147.69             84.10     62.79
## 2       294.15      119.10        54.04             27.92     39.37
## 3      1018.35      536.52       303.35             91.85     66.17
## 4      2518.85      971.87       725.12            160.00    130.17
## 5       515.18      287.71       129.60             52.40     40.71
##   bagpegCandy_units isotonics_units singleServePotato_units
## 1             36.12           71.02                   29.37
## 2              3.96           22.31                   11.65
## 3             28.94           65.50                   28.13
## 4             62.37          195.67                   89.00
## 5             12.58           56.69                   19.92
##   takeHomePotato_units kingBars_units flatWater_units psd591Ml_units
## 1                22.42          40.94          110.40          28.79
## 2                 3.38          15.56           39.21          39.87
## 3                33.38          35.63           74.50          42.69
## 4                61.13          65.42          256.79          60.67
## 5                 4.90          28.88           69.08          24.46
n_distinct(df$city)
## [1] 256
n_distinct(df$region)
## [1] 4
unique(df$city)
##   [1] "BROCKVILLE"               "BURLINGTON"              
##   [3] "DON MILLS"                "NORTH YORK"              
##   [5] "ETOBICOKE"                "GEORGETOWN"              
##   [7] "GORMLEY"                  "GUELPH"                  
##   [9] "HAMILTON"                 "STONEY CREEK"            
##  [11] "KANATA"                   "KITCHENER"               
##  [13] "LONDON"                   "UNIONVILLE"              
##  [15] "SCARBOROUGH"              "MILTON"                  
##  [17] "MISSISSAUGA"              "NEPEAN"                  
##  [19] "NEWMARKET"                "ORLEANS"                 
##  [21] "OTTAWA"                   "GLOUCESTER"              
##  [23] "PICKERING"                "PORT HOPE"               
##  [25] "RICHMOND HILL"            "ST. CATHARINES"          
##  [27] "ST THOMAS"                "SUDBURY"                 
##  [29] "THORNHILL"                "VAUGHAN"                 
##  [31] "TORONTO"                  "CONCORD"                 
##  [33] "WHITBY"                   "WIARTON"                 
##  [35] "WINDSOR"                  "WOODBRIDGE"              
##  [37] "UNKNOWN"                  "AJAX"                    
##  [39] "OAKVILLE"                 "TECUMSEH"                
##  [41] "BRAMPTON"                 "ARTHUR"                  
##  [43] "AURORA"                   "BARRIE"                  
##  [45] "BOLTON"                   "CALGARY"                 
##  [47] "FORT ST. JOHN"            "QUESNEL"                 
##  [49] "EDMONTON"                 "ROCKY MOUNTAIN HOUSE"    
##  [51] "CHASE"                    "MAPLE RIDGE"             
##  [53] "PORT COQUITLAM"           "WINFIELD"                
##  [55] "SURREY"                   "KAMLOOPS"                
##  [57] "VANCOUVER"                "KELOWNA"                 
##  [59] "REGINA"                   "ABBOTSFORD"              
##  [61] "MISSION"                  "WEST VANCOUVER"          
##  [63] "WINNIPEG"                 "VICTORIA"                
##  [65] "SASKATOON"                "ST. ALBERT"              
##  [67] "NANOOSE BAY"              "WILLIAMS LAKE"           
##  [69] "SALMON ARM"               "LANGLEY"                 
##  [71] "LAKE LOUISE"              "BURNABY"                 
##  [73] "RICHMOND"                 "PRINCE GEORGE"           
##  [75] "LADNER"                   "JASPER"                  
##  [77] "GRAND FORKS"              "LOGAN LAKE"              
##  [79] "WESTBANK"                 "NIAGARA-ON-THE-LAKE"     
##  [81] "BOWMANVILLE"              "OSHAWA"                  
##  [83] "COURTICE"                 "ST CATHARINES"           
##  [85] "WELLAND"                  "MARKHAM"                 
##  [87] "ORILLIA"                  "WILLOWDALE"              
##  [89] "DOWNSVIEW"                "EMERYVILLE"              
##  [91] "CAMBRIDGE"                "WATERLOO"                
##  [93] "STRATFORD"                "CHATHAM"                 
##  [95] "SARNIA"                   "DORCHESTER"              
##  [97] "L'ASSOMPTION"             "MONTRÉAL"               
##  [99] "BÉCANCOUR"               "LAVAL"                   
## [101] "SAINTE-JULIE"             "DELSON"                  
## [103] "SAINT-JEAN-PORT-JOLI"     "STONEHAM-ET-TEWKESBURY"  
## [105] "QUÉBEC"                  "HALIFAX"                 
## [107] "FALL RIVER"               "BEDFORD"                 
## [109] "DARTMOUTH"                "STEWIACKE"               
## [111] "LOWER SACKVILLE"          "CAP-ROUGE"               
## [113] "SAINT-HUBERT"             "DOLLARD DES ORMEAUX"     
## [115] "GREENFIELD PARK"          "ST-LAURENT"              
## [117] "STE-HÉLÈNE-DE-BAGOT"    "DORVAL"                  
## [119] "LACHINE"                  "BOUCHERVILLE"            
## [121] "SAINT-LÉONARD"           "LONGUEUIL"               
## [123] "BROSSARD"                 "NEUFCHATEL"              
## [125] "CHATEAUGUAY"              "MONTRÉAL NORD"          
## [127] "ANJOU"                    "SAINT-HYACINTHE"         
## [129] "KIRKLAND"                 "DRUMMONDVILLE"           
## [131] "SAINT-LAURENT"            "GATINEAU"                
## [133] "BOISBRIAND"               "SAINT-MATHIEU-DE-BELOEIL"
## [135] "ANCIENNE-LORETTE"         "CANDIAC"                 
## [137] "VAUDREUIL"                "ANGE GARDIEN DE ROUVILLE"
## [139] "TROIS-RIVIÈRES"          "MONCTON"                 
## [141] "MIRABEL"                  "VILLE MONT ROYAL"        
## [143] "ST-JÉRÔME"              "VERDUN"                  
## [145] "BEAUPORT"                 "REPENTIGNY"              
## [147] "MONT-TREMBLANT"           "SAINT JOHN"              
## [149] "BROMONT"                  "VANIER"                  
## [151] "SHERBROOKE"               "NORTH RIVER"             
## [153] "BERTHIERVILLE"            "TANTALLON"               
## [155] "ST-NICOLAS"               "LACHENAIE"               
## [157] "MASCOUCHE"                "ELMSDALE"                
## [159] "LÉVIS"                   "BLAINVILLE"              
## [161] "TERREBONNE"               "LAPRAIRIE"               
## [163] "BELOEIL"                  "LES CEDRES"              
## [165] "CAP ST-IGNACE"            "L'ISLET"                 
## [167] "LA POCATIÈRE"            "SAINT-PHILIPPE"          
## [169] "RIVIÈRE DU LOUP"         "RIVIÈRE-DU-LOUP"        
## [171] "TROIS-PISTOLES"           "BRANTFORD"               
## [173] "KINGSTON"                 "THUNDER BAY"             
## [175] "PETERBOROUGH"             "CUMBERLAND"              
## [177] "STITTSVILLE"              "BRADFORD"                
## [179] "PARRY SOUND"              "NIAGARA FALLS"           
## [181] "MAIDSTONE"                "LEDUC"                   
## [183] "SPRUCE GROVE"             "MEDICINE HAT"            
## [185] "WETASKIWIN"               "DUGALD"                  
## [187] "STONY PLAIN"              "CHILLIWACK"              
## [189] "GRANDE PRAIRIE"           "MORRIS"                  
## [191] "LANGENBURG"               "AIRDRIE"                 
## [193] "FORT MCMURRAY"            "SHERWOOD PARK"           
## [195] "ACHESON"                  "CHESTERMERE"             
## [197] "ALDERSYDE"                "ROCKY VIEW"              
## [199] "CALEDON"                  "CAMPBELLVILLE"           
## [201] "WATERDOWN"                "DUNDAS"                  
## [203] "SUTTON WEST"              "NIPIGON"                 
## [205] "BELLEVILLE"               "NAPANEE"                 
## [207] "SMITHVILLE"               "SCHOMBERG"               
## [209] "LAC DU BONNET"            "BRANDON"                 
## [211] "PORTAGE LA PRAIRIE"       "SELKIRK"                 
## [213] "OAK BLUFF"                "CORNWALL"                
## [215] "KESWICK"                  "TRENTON"                 
## [217] "WOODSTOCK"                "COBOURG"                 
## [219] "ST. THOMAS"               "THORNTON"                
## [221] "HAVELOCK"                 "ACTON"                   
## [223] "INGERSOLL"                "OWEN SOUND"              
## [225] "HORNBY"                   "BEAVERTON"               
## [227] "MERRITT"                  "PEMBERTON"               
## [229] "GIBSONS"                  "COQUITLAM"               
## [231] "PEACHLAND"                "VERNON"                  
## [233] "YORKTON"                  "MOOSE JAW"               
## [235] "NORTH BATTLEFORD"         "NISKU"                   
## [237] "BATTLEFORD"               "CANMORE"                 
## [239] "RED DEER"                 "HINTON"                  
## [241] "LETHBRIDGE"               "NORTH VANCOUVER"         
## [243] "HOPE"                     "PORT ALBERNI"            
## [245] "CAMPBELL RIVER"           "COURTENAY"               
## [247] "WHITE ROCK"               "NEW WESTMINSTER"         
## [249] "TSAWWASSEN"               "NANAIMO"                 
## [251] "SORRENTO"                 "VALEMOUNT"               
## [253] "PORT MOODY"               "DELTA"                   
## [255] "PRINCETON"                "SOOKE"

Summary:

The data set has 771 observations across 20 variables. The variable size shows 15 NA’s to now be numeric. The variable revenue variable equals character type. 4 unique regions and 256 unique cities.

3 - Convert revenue to numeric

df$revenue <- as.numeric(df$revenue)
## Warning: NAs introduced by coercion
str(df)
## 'data.frame':    771 obs. of  20 variables:
##  $ store                  : int  105 117 122 123 182 183 186 194 227 233 ...
##  $ city                   : chr  "BROCKVILLE" "BURLINGTON" "BURLINGTON" "BURLINGTON" ...
##  $ region                 : chr  "ONTARIO" "ONTARIO" "ONTARIO" "ONTARIO" ...
##  $ province               : chr  "ON" "ON" "ON" "ON" ...
##  $ size                   : int  496 875 691 763 784 NA 966 710 973 967 ...
##  $ revenue                : num  985 2629 2787 2834 4118 ...
##  $ units                  : num  470 1131 1229 1258 1950 ...
##  $ cost                   : num  591 1622 1709 1720 2486 ...
##  $ gross_profit           : num  394 1008 1077 1115 1633 ...
##  $ promo_units            : num  210 401 450 477 665 ...
##  $ energy_units           : num  72.1 192.8 240.5 194.2 199.7 ...
##  $ regularBars_units      : num  38.6 75 93.7 99.4 175.5 ...
##  $ gum_units              : num  29.3 55.9 64.3 73.2 145.8 ...
##  $ bagpegCandy_units      : num  13.4 42.1 29.9 54.1 68.1 ...
##  $ isotonics_units        : num  20.7 87.6 105.7 118.2 109.3 ...
##  $ singleServePotato_units: num  18.6 36.4 48 39.7 85.7 ...
##  $ takeHomePotato_units   : num  7.71 33.46 19.9 22.1 42.33 ...
##  $ kingBars_units         : num  17.9 47.4 45.2 45.3 79.8 ...
##  $ flatWater_units        : num  56.5 98.4 130.3 132.8 204.1 ...
##  $ psd591Ml_units         : num  39.7 38.7 47.3 39.9 50.3 ...

4 - Delete rows with missing values

df <- na.omit(df)

5 - df_low and df_high

mean(df$revenue)
## [1] 3628.561
df_low <- df %>% filter(revenue < 3628)
mean(df_low$size)
## [1] 679.6025
mean(df$revenue)
## [1] 3628.561
df_high <- df %>% filter(revenue >= 3628)
mean(df_high$size)
## [1] 882.4929

Comment about the relationship between revenue and size by discussing means.

Average size of df_low is 679.6 and Average size of df_high is 882.

6 - Correlation betweeen revenue and size

cor(df$revenue, df$size)
## [1] 0.6175055
ggplot(df, aes(x=size, y=revenue)) + geom_point()

Comment on the output from above.

When the size increases, revenue increases as well.

7 - Boxplots of revenue for each region

ggplot(df, aes(x=region, y=revenue)) +
  geom_boxplot() + 
  labs(title = 'Boxplots of Revenue by Region')

Comment summary distribution of revenue within each region.

Atlantic area shows no outliers within range of revenue values. Ontario area shows most concentrated for revenue value. Quebec region shows small range of revenue values very few outliers. West region reflects a big range of revenue values, with the largest amount of outliers with highest revenue outliers.

8 - Bar chart of gross_profit for each province

province <- df %>% group_by(province) %>% summarize(sum_revenue = sum(revenue))
print(province)
## # A tibble: 10 × 2
##    province sum_revenue
##    <chr>          <dbl>
##  1 AB           542720.
##  2 BC           419288.
##  3 MB            84681.
##  4 NB            13869.
##  5 NS            44021.
##  6 ON          1046387.
##  7 PE             4511.
##  8 QC           470365.
##  9 SK            83426.
## 10 UNKNOWN       30296.
ggplot(data = df, aes(x = province, y = revenue)) + 
  geom_col() + 
  scale_y_continuous(labels = scales::unit_format(unit = "M", scale = 1e-6)) +
  labs(title = 'Total Gross Profit by Province')

Summary Comment:

Ontario has the highest total gross profit which surpasses profits of other provinces. Alberta is second, Quebec shows to be third. British Columbia and Saskatchewan reflects less total gross profits in comparison to the top producing provinces.

9 - Correlation matrix of average store sales for product categories

correlation_matrix <- cor(df[,11:20])
correlation_matrix
##                         energy_units regularBars_units gum_units
## energy_units               1.0000000         0.7940865 0.7791820
## regularBars_units          0.7940865         1.0000000 0.7430876
## gum_units                  0.7791820         0.7430876 1.0000000
## bagpegCandy_units          0.7578455         0.9127088 0.6865389
## isotonics_units            0.8837228         0.8913260 0.7204674
## singleServePotato_units    0.7856168         0.9105970 0.6758916
## takeHomePotato_units       0.7504980         0.8823330 0.6710437
## kingBars_units             0.7960175         0.9015765 0.6322488
## flatWater_units            0.7855815         0.8772875 0.7031540
## psd591Ml_units             0.8139704         0.8402457 0.5849746
##                         bagpegCandy_units isotonics_units
## energy_units                    0.7578455       0.8837228
## regularBars_units               0.9127088       0.8913260
## gum_units                       0.6865389       0.7204674
## bagpegCandy_units               1.0000000       0.9046627
## isotonics_units                 0.9046627       1.0000000
## singleServePotato_units         0.8725405       0.8825922
## takeHomePotato_units            0.9237664       0.8697460
## kingBars_units                  0.8739585       0.9024568
## flatWater_units                 0.8637856       0.8905652
## psd591Ml_units                  0.8275502       0.8766410
##                         singleServePotato_units takeHomePotato_units
## energy_units                          0.7856168            0.7504980
## regularBars_units                     0.9105970            0.8823330
## gum_units                             0.6758916            0.6710437
## bagpegCandy_units                     0.8725405            0.9237664
## isotonics_units                       0.8825922            0.8697460
## singleServePotato_units               1.0000000            0.8676895
## takeHomePotato_units                  0.8676895            1.0000000
## kingBars_units                        0.8782217            0.8523930
## flatWater_units                       0.9184280            0.8275743
## psd591Ml_units                        0.8880491            0.8205825
##                         kingBars_units flatWater_units psd591Ml_units
## energy_units                 0.7960175       0.7855815      0.8139704
## regularBars_units            0.9015765       0.8772875      0.8402457
## gum_units                    0.6322488       0.7031540      0.5849746
## bagpegCandy_units            0.8739585       0.8637856      0.8275502
## isotonics_units              0.9024568       0.8905652      0.8766410
## singleServePotato_units      0.8782217       0.9184280      0.8880491
## takeHomePotato_units         0.8523930       0.8275743      0.8205825
## kingBars_units               1.0000000       0.8638809      0.8641337
## flatWater_units              0.8638809       1.0000000      0.8388392
## psd591Ml_units               0.8641337       0.8388392      1.0000000
  1. Product categories that sell together the least.
  2. Product categories that sell together the most.
max_corr <- max(correlation_matrix)
min_corr <- min(correlation_matrix)
indices_max_corr <- which(correlation_matrix == max_corr, arr.ind = TRUE)
indices_min_corr <- which(correlation_matrix == min_corr, arr.ind = TRUE)
product_categories <- colnames(correlation_matrix)
category1_max_corr <- product_categories[indices_max_corr[1, 2]]
category2_max_corr <- product_categories[indices_max_corr[1, 1]]
category1_min_corr <- product_categories[indices_min_corr[1, 2]]
category2_min_corr <- product_categories[indices_min_corr[1, 1]]
correlation_matrix
##                         energy_units regularBars_units gum_units
## energy_units               1.0000000         0.7940865 0.7791820
## regularBars_units          0.7940865         1.0000000 0.7430876
## gum_units                  0.7791820         0.7430876 1.0000000
## bagpegCandy_units          0.7578455         0.9127088 0.6865389
## isotonics_units            0.8837228         0.8913260 0.7204674
## singleServePotato_units    0.7856168         0.9105970 0.6758916
## takeHomePotato_units       0.7504980         0.8823330 0.6710437
## kingBars_units             0.7960175         0.9015765 0.6322488
## flatWater_units            0.7855815         0.8772875 0.7031540
## psd591Ml_units             0.8139704         0.8402457 0.5849746
##                         bagpegCandy_units isotonics_units
## energy_units                    0.7578455       0.8837228
## regularBars_units               0.9127088       0.8913260
## gum_units                       0.6865389       0.7204674
## bagpegCandy_units               1.0000000       0.9046627
## isotonics_units                 0.9046627       1.0000000
## singleServePotato_units         0.8725405       0.8825922
## takeHomePotato_units            0.9237664       0.8697460
## kingBars_units                  0.8739585       0.9024568
## flatWater_units                 0.8637856       0.8905652
## psd591Ml_units                  0.8275502       0.8766410
##                         singleServePotato_units takeHomePotato_units
## energy_units                          0.7856168            0.7504980
## regularBars_units                     0.9105970            0.8823330
## gum_units                             0.6758916            0.6710437
## bagpegCandy_units                     0.8725405            0.9237664
## isotonics_units                       0.8825922            0.8697460
## singleServePotato_units               1.0000000            0.8676895
## takeHomePotato_units                  0.8676895            1.0000000
## kingBars_units                        0.8782217            0.8523930
## flatWater_units                       0.9184280            0.8275743
## psd591Ml_units                        0.8880491            0.8205825
##                         kingBars_units flatWater_units psd591Ml_units
## energy_units                 0.7960175       0.7855815      0.8139704
## regularBars_units            0.9015765       0.8772875      0.8402457
## gum_units                    0.6322488       0.7031540      0.5849746
## bagpegCandy_units            0.8739585       0.8637856      0.8275502
## isotonics_units              0.9024568       0.8905652      0.8766410
## singleServePotato_units      0.8782217       0.9184280      0.8880491
## takeHomePotato_units         0.8523930       0.8275743      0.8205825
## kingBars_units               1.0000000       0.8638809      0.8641337
## flatWater_units              0.8638809       1.0000000      0.8388392
## psd591Ml_units               0.8641337       0.8388392      1.0000000