# 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, 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:
Product_ID: A unique identifier, between 1 and 120, for every pizza product is contained in this field. By using its Product ID, each product is given a unique identity that keeps it consistent with other datasets.
Pizza_Type: This column indicates the kind of pizza that was ordered; choices include Hawaiian, Margherita, Pepperoni, and Vegetarian. To replicate real-world diversity, different types of pizza are assigned at random to each order.
Pizza_Size: This parameter, which might be Small, Medium, or Large, describes the size of the pizza that was ordered. To ensure variation, the sizes are allocated at random to every order.
Price: To simulate real pricing, the price of each pizza is indicated in this field, which is produced using a random uniform distribution between $5 and $20.
Customer_Age: This parameter, which ranges from 18 to 60 years old, indicates the customer’s age at the time of order placement. To replicate a broad client base, the ages are allocated at random.
Customer_Gender: This field, which has the options Male and Female, indicates the customer’s gender at the time the order is placed. For diversity, the genders are assigned at random.
Order_Time: This column uses a 24-hour format to indicate the exact time the order was placed (0-23). For every order, a random order time is assigned.
Adjusted_Price_Variation: This variable is created as a correlated version of the original Price variable from the dominos_reservior_1 dataset. It includes random noise sampled from a normal distribution with a mean of 0 and a standard deviation of 5. This variable represents an adjusted or modified version of the product price, which can be useful for analyzing pricing strategies or customer purchasing behavior in relation to the original prices.
Additionally, I have included missing values in the Price column to improve the dataset’s realism; these values affect about 5% of the total rows. This simulates real-world situations in which records of some transactions may be missing or incomplete.
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:
Product_ID: A unique identifier, between 1 and 120, for every pizza product is contained in this field. By using its Product ID, each product is given a unique identity that keeps it consistent with other datasets.
Duration: To reflect actual delivery time frames, this variable indicates the delivery’s duration in minutes, sampled from 15 to 59 minutes.
Customer_Rating: To simulate different levels of satisfaction, a uniform distribution between 3 and 5 is used to construct the rating that the client provided for the delivery.
Customer_Review: Classified as ‘Good’, ‘Average’, or ‘Poor’, this field indicates the customer’s assessment of the delivery. For every delivery, a random assignment of reviews is made.
Delivery_Location: This parameter, which can be set to “Home,” “Office,” or “School,” indicates where the delivery is being made. To replicate a variety of delivery places, the locations are assigned at random.
Delivery_Driver: This field, which has identifiers ranging from “Driver 1” to “Driver 50,” indicates the delivery driver in charge of the delivery. To ensure diversity, the drivers are paired at random with each delivery.
Delivery_Time_Adjusted: This variable is created as a correlated version of the original Duration variable from the dominos_reservior_2 dataset. It includes random noise sampled from a normal distribution with a mean of 0 and a standard deviation of 5. This variable represents an adjusted or modified version of the delivery time, which can be useful for analyzing delivery efficiency or performance in relation to the original delivery times.
Furthermore, In order to improve the dataset’s realism, I’ve added missing values to the Customer_Review and Duration columns, which will impact about 5% of the total rows. This is consistent with real-world situations where some data items might not be recorded for every entry or might be missing altogether.
# 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)
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.
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.
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.
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.
# 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)
The merged_dominos_reservior dataset’s structure is shown using the str function. Details regarding the variables and data types in the dataset are provided by this function.
Important information about the dataset is revealed in the function’s output, including the number of variables (columns) and observations (rows), as well as the data types associated with each variable. This data can aid in additional data processing and analysis and is essential for comprehending the dataset.
Delivery_Location and Customer_Gender are variables that I converted from character type to factor during the data type conversion process. This conversion is essential for categorical variables since it makes data management and analysis more effective. By classifying the data into discrete levels, factors facilitate more accurate statistical analysis and interpretation. Furthermore, this conversion guarantees that these variables are handled correctly in later studies, improving the process’s overall quality of data analysis.
# 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>
Grouping by Pizza Type: The group_by function is used to group the data according to the Pizza_Type field.
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.
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.
# 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
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.
Impute missing values: Several variables with missing values are then imputed:
Adjusted_Price_Variation: Missing values are replaced with the mean of the non-missing values in the same column.
Customer_Review: Missing values are filled with the mode (most frequent value) of the Customer_Review variable.
Duration: Missing values are imputed with the mean of the Duration variable.
Price: Missing values are imputed with the mean of the Price variable.
Delivery_Time_Adjusted: Missing values are imputed with the mean of the Delivery_Time_Adjusted variable.
# Add the link to your presentation here.
Presentation Link:- https://rmit-arc.instructuremedia.com/embed/5d2d7016-f0ed-4a20-a56c-5127afea63d0
REFERENCES :
Wickham, H., François, R., Henry, L., & Müller, K. (2021). dplyr: A grammar of data manipulation (Version 1.1.4) [Computer software], accessed 28 April 2024, https://cran.r-project.org/package=dplyr
Quillbot Paraphrasing Tool: Utilized for documentation purposes, accessed 30 April 2024, https://quillbot.com/
RMIT. (2024). Module 3: Understand: Understanding Data and Data Structures, Data Wrangling (preprocessing), accessed 23 April, https://rare-phoenix-161610.appspot.com/secured/Module_03.html
RMIT. (2024). Module 4: Tidy and Manipulate: Tidy Data Principles and Manipulating Data, Data Wrangling (Preprocessing), accessed 25 April 2024, https://rare-phoenix-161610.appspot.com/secured/Module_04.html
RMIT. (2024). Module 5: Scan - Missing Values, Data Wrangling (Preprocessing), accessed 25 April 2024, https://rare-phoenix-161610.appspot.com/secured/Module_05.html