This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(readr)
DodgersData <- read_csv("DodgersData.csv")
## Rows: 81 Columns: 12
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): month, day_of_week, opponent, skies, day_night, cap, shirt, firewor...
## dbl (3): day, attend, temp
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
mean_attend <- mean(DodgersData$attend, na.rm = TRUE)
median_attend <- median(DodgersData$attend, na.rm = TRUE)
print(mean_attend)
## [1] 41040.07
print(median_attend)
## [1] 40284
library(ggplot2)
ggplot(DodgersData, aes(x = month, y = attend)) +
geom_boxplot(fill = "steelblue") +
labs(
title = "Dodgers Attendance by Month",
x = "Month",
y = "Attendance"
) +
theme_minimal()
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
attendance_type <- DodgersData %>%
mutate(day_type = case_when(
day_of_week %in% c("Saturday", "Sunday") ~ "Weekend",
TRUE ~ "Weekday"
)) %>%
group_by(day_type) %>%
summarise(mean_attendance = mean(attend, na.rm = TRUE))
ggplot(attendance_type, aes(x = day_type, y = mean_attendance, fill = day_type)) +
geom_col() +
labs(
title = "Average Dodgers Attendance: Weekday vs. Weekend",
x = "Day Type",
y = "Average Attendance"
) +
theme_minimal() +
theme(legend.position = "none")
```