library(ggplot2)
data <- read.csv("DodgersData.csv",
stringsAsFactors = FALSE)
head(data)
## month day attend day_of_week opponent temp skies day_night cap shirt
## 1 APR 10 56000 Tuesday Pirates 67 Clear Day NO NO
## 2 APR 11 29729 Wednesday Pirates 58 Cloudy Night NO NO
## 3 APR 12 28328 Thursday Pirates 57 Cloudy Night NO NO
## 4 APR 13 31601 Friday Padres 54 Cloudy Night NO NO
## 5 APR 14 46549 Saturday Padres 57 Cloudy Night NO NO
## 6 APR 15 38359 Sunday Padres 65 Clear Day NO NO
## fireworks bobblehead
## 1 NO NO
## 2 NO NO
## 3 NO NO
## 4 YES NO
## 5 NO NO
## 6 NO NO
names(data)
## [1] "month" "day" "attend" "day_of_week" "opponent"
## [6] "temp" "skies" "day_night" "cap" "shirt"
## [11] "fireworks" "bobblehead"
Question 1: Attendance
median_attendance <- median(data$attend, na.rm = TRUE)
mean_attendance <- mean(data$attend, na.rm = TRUE)
median_attendance
## [1] 40284
mean_attendance
## [1] 41040.07
Question 2: Histogram
ggplot(data, aes(x = attend)) +
geom_histogram(
binwidth = 5000,
fill = "blue",
color = "white"
) +
labs(
title = "Distribution of Dodgers Game Attendance",
x = "Attendance",
y = "Number of Games"
) +
theme_minimal()
