The Walmart Sales dataset is related to marketing because it contains weekly store sales and business factors that may influence consumer purchasing behavior. The dataset includes sales, holidays, temperature, fuel prices, CPI, and unemployment.
# Import the dataset
walmart <- read.csv("Walmart_Sales.csv")
# View the first few observations
head(walmart)
## Store Date Weekly_Sales Holiday_Flag Temperature Fuel_Price CPI
## 1 1 05-02-2010 1643691 0 42.31 2.572 211.0964
## 2 1 12-02-2010 1641957 1 38.51 2.548 211.2422
## 3 1 19-02-2010 1611968 0 39.93 2.514 211.2891
## 4 1 26-02-2010 1409728 0 46.63 2.561 211.3196
## 5 1 05-03-2010 1554807 0 46.50 2.625 211.3501
## 6 1 12-03-2010 1439542 0 57.79 2.667 211.3806
## Unemployment
## 1 8.106
## 2 8.106
## 3 8.106
## 4 8.106
## 5 8.106
## 6 8.106
# Display the original number of observations and variables
original_rows <- nrow(walmart)
original_columns <- ncol(walmart)
cat("Original number of observations:", original_rows, "\n")
## Original number of observations: 6435
cat("Original number of variables:", original_columns, "\n")
## Original number of variables: 8
# Select approximately half of the observations
set.seed(42)
sample_size <- ceiling(original_rows / 2)
walmart_sample <- walmart[
sample(
1:original_rows,
size = sample_size,
replace = FALSE
),
]
cat("Sample size used for analysis:", nrow(walmart_sample), "\n")
## Sample size used for analysis: 3218
cat(
"Percentage of original data used:",
round(nrow(walmart_sample) / original_rows * 100, 2),
"%\n"
)
## Percentage of original data used: 50.01 %
The original dataset contains 6,435 observations and 8 variables. Approximately half of the observations, or 3,218 rows, were selected for this analysis.
This analysis compares weekly sales during holidays and non-holidays.
# Calculate average, median, minimum, and maximum sales
holiday_average <- aggregate(
Weekly_Sales ~ Holiday_Flag,
data = walmart_sample,
FUN = mean
)
holiday_median <- aggregate(
Weekly_Sales ~ Holiday_Flag,
data = walmart_sample,
FUN = median
)
holiday_minimum <- aggregate(
Weekly_Sales ~ Holiday_Flag,
data = walmart_sample,
FUN = min
)
holiday_maximum <- aggregate(
Weekly_Sales ~ Holiday_Flag,
data = walmart_sample,
FUN = max
)
holiday_count <- table(walmart_sample$Holiday_Flag)
# Combine results into one table
holiday_summary <- data.frame(
Holiday_Status = c("Non-holiday", "Holiday"),
Observations = as.numeric(holiday_count),
Average_Sales = holiday_average$Weekly_Sales,
Median_Sales = holiday_median$Weekly_Sales,
Minimum_Sales = holiday_minimum$Weekly_Sales,
Maximum_Sales = holiday_maximum$Weekly_Sales
)
holiday_summary
## Holiday_Status Observations Average_Sales Median_Sales Minimum_Sales
## 1 Non-holiday 2988 1031257 946332.5 209986.2
## 2 Holiday 230 1126962 1002617.1 241937.1
## Maximum_Sales
## 1 3766687
## 2 3004702
boxplot(
Weekly_Sales ~ Holiday_Flag,
data = walmart_sample,
names = c("Non-holiday", "Holiday"),
main = "Weekly Sales During Holidays and Non-Holidays",
xlab = "Sales Period",
ylab = "Weekly Sales ($)",
col = c("lightblue", "lightgreen")
)
This analysis examines whether fuel prices are related to weekly sales.
# Calculate the correlation between fuel price and weekly sales
sales_fuel_correlation <- cor(
walmart_sample$Fuel_Price,
walmart_sample$Weekly_Sales,
use = "complete.obs"
)
cat(
"Correlation between fuel price and weekly sales:",
round(sales_fuel_correlation, 3),
"\n"
)
## Correlation between fuel price and weekly sales: 0.015
plot(
walmart_sample$Fuel_Price,
walmart_sample$Weekly_Sales,
main = "Relationship Between Fuel Price and Weekly Sales",
xlab = "Fuel Price",
ylab = "Weekly Sales ($)",
pch = 19,
col = "steelblue"
)
# Add a trend line
abline(
lm(Weekly_Sales ~ Fuel_Price, data = walmart_sample),
col = "red",
lwd = 2
)
summary(walmart_sample$Weekly_Sales)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 209986 547570 951560 1038097 1404267 3766687
cat(
"Standard deviation of weekly sales:",
round(sd(walmart_sample$Weekly_Sales), 2),
"\n"
)
## Standard deviation of weekly sales: 565515.2
cat(
"Lowest weekly sales:",
round(min(walmart_sample$Weekly_Sales), 2),
"\n"
)
## Lowest weekly sales: 209986.2
cat(
"Highest weekly sales:",
round(max(walmart_sample$Weekly_Sales), 2),
"\n"
)
## Highest weekly sales: 3766687
The holiday comparison showed that average weekly sales were slightly higher during holidays than during non-holiday periods. The correlation analysis showed that fuel price had a very weak relationship with weekly sales in the selected sample. These results suggest that holiday timing may be more useful for marketing planning than fuel price alone, although other factors such as store location, promotions, and customer demographics may also influence sales.