Setup

# Load the necessary packages required to reproduce the report. 
library(dplyr)
## 
## 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

Data generation

# Data generation, provide your R codes here.

# Set seed for reproducibility
set.seed(799)

# Define the number of rows in each dataset
n_rows <- 120

# Dataset 1 using domino's 
dominos_reservior_1 <- data.frame(
  Product_ID = sample(1:120, n_rows),
  Pizza_Type = sample(c('Margherita', 'Pepperoni', 'Vegetarian', 'Hawaiian'), n_rows, replace = TRUE),
  Pizza_Size = sample(c('Small', 'Medium', 'Large'), n_rows, replace = TRUE),
  Price = round(runif(n_rows, 5, 20), 2),
  Customer_Age = sample(18:60, n_rows, replace = TRUE),
  Customer_Gender = sample(c('Male', 'Female'), n_rows, replace = TRUE),
  Order_Time = sample(0:23, n_rows, replace = TRUE) # Order Time (24 hour format)
  
)

# Get the number of rows in the dataset
n_rows <- nrow(dominos_reservior_1)

# Calculate the number of rows to be set as NA (5% of total rows)
n_sample <- round(n_rows * 0.05)

# Randomly select rows to set Price as NA
random_rows <- sample(1:n_rows, n_sample)

# Set Price as NA for the randomly selected rows
dominos_reservior_1$Price[random_rows] <- NA

#introducing the correlated variable
# Create a correlated variable based on Price with some noise
Adjusted_Price_Variation <- dominos_reservior_1$Price + rnorm(n_rows, mean = 0, sd = 5)

# Add the correlated variable to the dataset
dominos_reservior_1$Adjusted_Price_Variation <- Adjusted_Price_Variation

# Display head of the dataset of dominos_reservior_1
head(dominos_reservior_1)
# Dataset 2 using domino's 

# number of rows in the data frame
n_rows <- 120

dominos_reservior_2 <- data.frame(
  Product_ID = sample(1:120, n_rows,replace=TRUE),
  Duration= sample(15:59, n_rows, replace = TRUE),
  Customer_Rating = round(runif(n_rows, 3, 5), 1),
  Customer_Review = sample(c('Good', 'Average', 'Poor'), n_rows, replace = TRUE),
  Delivery_Location = sample(c('Home', 'Office', 'School'), n_rows, replace = TRUE),
  Delivery_Driver = sample(paste('Driver', 1:50), n_rows, replace = TRUE) # Delivery Driver
)

# Calculate the number of rows to be set as NA (5% of total rows)
n_sample <- round(n_rows * 0.05)

# Randomly select rows to set Customer_Review and Duration as NA
random_rows <- sample(1:n_rows, n_sample)

# Set Customer_Review as NA for the randomly selected rows
dominos_reservior_2$Customer_Review[random_rows] <- NA

# Set Duration as NA for the randomly selected rows
dominos_reservior_2$Duration[random_rows] <- NA

# Create a correlated variable based on Duration with some noise
Delivery_Time_Adjusted <- dominos_reservior_2$Duration + rnorm(n_rows, mean = 0, sd = 5)

# Add the correlated variable to the dataset
dominos_reservior_2$Delivery_Time_Adjusted <- Delivery_Time_Adjusted

# Display head of the dataset of dominos_reservior_2
head(dominos_reservior_2)

To meet the assessment standards, I’m approaching this task as a data analyst for Domino’s located at reservior, Melbourne, a major participant in the food delivery market. I’ve been entrusted with creating synthetic data related to Domino’s operations. This entails constructing two synthetic datasets. dominos_reservior_1: This collection includes pizza orders placed at Domino’s. dominos_reservior_2: This dataset contains information regarding customer ratings and delivery details.

Dataset 1: Domino’s Pizza Orders

To begin, I’ve initialized the seed value as 799 and set the dataset’s dimensions to 120 rows and 7 columns, meeting the specified minimum requirements.Let’s explore each domain in more detail:

Dataset 2: Domino’s Delivery Details

In this dataset, named domino_reservoir_2, I’ve generated synthetic data related to the delivery aspects of Domino’s pizza orders. The dataset consists of 200 rows and 6 columns, meeting the assignment’s requirements. Let’s explore each field:

Merging data sets

# Merge your synthetic data sets, provide R codes here.

# Merge the two dominos datasets based on Product_ID
merged_dominos_reservior <- merge(dominos_reservior_1, dominos_reservior_2, by = "Product_ID")

# Convert Customer_Gender to a factor with labels "1: Male" and "2: Female"
merged_dominos_reservior$Customer_Gender <- factor(merged_dominos_reservior$Customer_Gender, levels =c("Male", "Female"), labels = c("1: Male","2: Female"))

# Convert Delivery_Location to a factor with labels "1: Home", "2: Office", and "3: School"
merged_dominos_reservior$Delivery_Location <- factor(merged_dominos_reservior$Delivery_Location, levels =c("Home", "Office", "School"), labels = c("Type 1: Home","Type 2: Office","Type 3: School"))

head(merged_dominos_reservior)
  1. To merge the two Domino’s datasets: I have used ‘merge’ function with the ‘by’ parameter set to ‘Product_ID’ to specify that the merge should be performed based on that column.

  2. After merging the two datasets, I have converted the ‘Customer_Gender’ variable into a factor. The gender categories are given the labels “1: Male” and “2: Female” by this conversion, making interpretation and analysis simpler.

  3. To represent several delivery locations, I have also transformed the Delivery_Location variable into a factor with the labels “Type 1: Home,” “Type 2: Office,” and “Type 3: School.” The classification and analysis of delivery locations are improved by this conversion.

  4. The combined dataset, merged_dominos_reservior, is now ready for additional analysis. After these changes, It consists of 13 variables, all of which provide insightful information on Domino’s pizza orders and delivery processes.

Checking structure of combined data

# Check structure of combined data and perform all necessary data type conversions, provide R codes here.

# Display the structure of the merged dataset
str(merged_dominos_reservior)
## 'data.frame':    120 obs. of  14 variables:
##  $ Product_ID              : int  1 3 3 6 6 6 9 13 14 14 ...
##  $ Pizza_Type              : chr  "Hawaiian" "Vegetarian" "Vegetarian" "Pepperoni" ...
##  $ Pizza_Size              : chr  "Small" "Large" "Large" "Small" ...
##  $ Price                   : num  7.85 17.45 17.45 13.19 13.19 ...
##  $ Customer_Age            : int  60 48 48 51 51 51 59 45 22 22 ...
##  $ Customer_Gender         : Factor w/ 2 levels "1: Male","2: Female": 1 2 2 1 1 1 1 1 2 2 ...
##  $ Order_Time              : int  8 19 19 2 2 2 0 7 7 7 ...
##  $ Adjusted_Price_Variation: num  3.35 19.02 19.02 16.51 16.51 ...
##  $ Duration                : int  32 25 32 NA 21 40 40 22 19 29 ...
##  $ Customer_Rating         : num  3.2 4.1 4.9 3.7 4.2 3.1 4.3 4.1 4.6 4 ...
##  $ Customer_Review         : chr  "Poor" "Good" "Average" NA ...
##  $ Delivery_Location       : Factor w/ 3 levels "Type 1: Home",..: 2 1 3 2 1 1 1 1 3 2 ...
##  $ Delivery_Driver         : chr  "Driver 44" "Driver 40" "Driver 2" "Driver 49" ...
##  $ Delivery_Time_Adjusted  : num  49.7 30.7 35.3 NA 28 ...
# Convert a character variable to factor
merged_dominos_reservior$Delivery_Location <- as.factor(merged_dominos_reservior$Delivery_Location)

# Convert another character variable to factor
merged_dominos_reservior$Customer_Gender <- as.factor(merged_dominos_reservior$Customer_Gender)

Generate summary statistics

# Generate summary statistics, provide R codes here.

# Calculate summary statistics and printing it.
summary_stats_dominos <- merged_dominos_reservior %>%
  group_by(Pizza_Type) %>%
  summarise(
    Pizza_Mean = mean(Price, na.rm = TRUE),
    Pizza_Median = median(Price, na.rm = TRUE),
    Pizza_1st_Quartile = quantile(Price, 0.25, na.rm = TRUE),
    Pizza_3rd_Quartile = quantile(Price, 0.75, na.rm = TRUE),
    Pizza_SD = sd(Price, na.rm = TRUE)
  )
print(summary_stats_dominos)
## # A tibble: 4 × 6
##   Pizza_Type Pizza_Mean Pizza_Median Pizza_1st_Quartile Pizza_3rd_Quartile
##   <chr>           <dbl>        <dbl>              <dbl>              <dbl>
## 1 Hawaiian         12.1         11.3               8.83               16.1
## 2 Margherita       11.5         10.8               9.52               14  
## 3 Pepperoni        12.6         13.2               7.44               17.8
## 4 Vegetarian       12.3         11.9              10.3                13.6
## # ℹ 1 more variable: Pizza_SD <dbl>
  1. Grouping by Pizza Type: The group_by function is used to group the data according to the Pizza_Type field.

  2. Calculating Summary Statistics: For every kind of pizza, the code computes multiple statistics using the summarize function: Pizza_Mean: The mean cost of each variety of pizza. Pizza_Median: The average cost of each variety of pizza. Pizza_1st_Quartile: The price of each variety in the first quartile (Q1). Pizza_3rd_Quartile: The pricing range for each type’s third quartile (Q3). Pizza_SD: The price standard deviation for every category.

  3. Printing Summary Statistics: Lastly, the computed summary statistics are shown using the print function.

A variety of pricing information is available from the summary statistics, including the average price, median price, standard deviation of price variability, quartiles of price distribution, and price variability for each type of pizza. These figures can be used to better analyze pricing patterns and variances across the many Domino’s pizza varieties.

Scanning data

# Scan variables for missing values.
missing_values <- colSums(is.na(merged_dominos_reservior))

# Print the count of missing values for each variable
print(missing_values)
##               Product_ID               Pizza_Type               Pizza_Size 
##                        0                        0                        0 
##                    Price             Customer_Age          Customer_Gender 
##                        7                        0                        0 
##               Order_Time Adjusted_Price_Variation                 Duration 
##                        0                        7                        6 
##          Customer_Rating          Customer_Review        Delivery_Location 
##                        0                        6                        0 
##          Delivery_Driver   Delivery_Time_Adjusted 
##                        0                        6
# Impute missing values for Adjusted_Price_Variation with the mean.
merged_dominos_reservior$Adjusted_Price_Variation[is.na(merged_dominos_reservior$Adjusted_Price_Variation)] <- mean(merged_dominos_reservior$Adjusted_Price_Variation, na.rm =TRUE)

# Impute missing values for Customer_Review with the mode.
merged_dominos_reservior$Customer_Review[is.na(merged_dominos_reservior$Customer_Review)] <- mode(merged_dominos_reservior$Customer_Review)

# Impute missing values for Duration with the mean.
merged_dominos_reservior$Duration [is.na(merged_dominos_reservior$Duration )] <- mean(merged_dominos_reservior$Duration , na.rm =TRUE)

# Impute missing values for Price with the mean.
merged_dominos_reservior$Price[is.na(merged_dominos_reservior$Price)] <- mean(merged_dominos_reservior$Price, na.rm =TRUE)

# Impute missing values for Delivery_Time_Adjusted with the mean.
merged_dominos_reservior$Delivery_Time_Adjusted[is.na(merged_dominos_reservior$Delivery_Time_Adjusted)] <- mean(merged_dominos_reservior$Delivery_Time_Adjusted, na.rm =TRUE)

# Rescan and print variables for missing values after imputation.
missing_values <- colSums(is.na(merged_dominos_reservior))
print(missing_values)
##               Product_ID               Pizza_Type               Pizza_Size 
##                        0                        0                        0 
##                    Price             Customer_Age          Customer_Gender 
##                        0                        0                        0 
##               Order_Time Adjusted_Price_Variation                 Duration 
##                        0                        0                        0 
##          Customer_Rating          Customer_Review        Delivery_Location 
##                        0                        0                        0 
##          Delivery_Driver   Delivery_Time_Adjusted 
##                        0                        0
  1. Scan variables for missing values: Initially, the code uses colSums(is.na(…)) to scan the merged_dominos_reservior dataset for missing values. This function calculates the sum of missing values for each variable and stores the results in the missing_values vector. Print the count of missing values: The print(missing_values) statement prints the count of missing values for each variable, providing an overview of the extent of missing data in the dataset.

  2. Impute missing values: Several variables with missing values are then imputed:

  1. Rescan and print variables for missing values after imputation: Finally, the code rescans the dataset for missing values using colSums(is.na(merged_dominos_reservior)) after the imputation process and prints the new count of missing values for each variable. This step ensures that missing values have been properly handled and imputed.