1.) Setup

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tibble)
library(knitr)
library(readr)
library(ggplot2)
movies <- read_csv("Desktop/RWorkingDirectory/Working Directory/summer_movies.csv")
## Rows: 7 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, fresh, superhero
## dbl (5): critic_score, audience_score, runtime_minutes, boxoffice, sequel
## 
## ℹ 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.
movies <- as_tibble(movies)

2.) Movie Information Table

library(knitr)

# Create a subset of your dataset containing only the desired columns
subset_data <- movies[, c("name", "runtime_minutes", "boxoffice")]

# Create the table using kable() with a caption
table <- kable(subset_data,"pipe", col.name=c("Movie Name", "Runtime (Minutes)", "Box Office Profit($)"), caption = "Movie Info", align = c('l','c','c'))

table
Movie Info
Movie Name Runtime (Minutes) Box Office Profit($)
Barbie 114 592.8
Oppenheimer 180 299.2
Spider-Man: Across the Spider-Verse 140 381.2
The Flash 144 108.1
Asteroid City 125 28.0
Guardians of the Galaxy Vol. 3 150 359.0
Indiana Jones and the Dial of Destiny 144 174.1

3.) Recode the “Sequel” Variable

movies$sequel <- ifelse(movies$sequel == 1, "Sequel", "Non-Sequel")
table2 <- kable(movies, "pipe")
table2
name critic_score audience_score fresh superhero runtime_minutes boxoffice sequel
Barbie 88 83 Fresh No 114 592.8 Non-Sequel
Oppenheimer 93 91 Fresh No 180 299.2 Non-Sequel
Spider-Man: Across the Spider-Verse 95 94 Fresh Yes 140 381.2 Sequel
The Flash 63 83 Not Fresh Yes 144 108.1 Non-Sequel
Asteroid City 75 62 Fresh No 125 28.0 Non-Sequel
Guardians of the Galaxy Vol. 3 82 94 Fresh Yes 150 359.0 Sequel
Indiana Jones and the Dial of Destiny 69 88 Not Fresh No 144 174.1 Sequel

4.) Subset the Dataset

# subset of sequels
sequels <- subset(movies, sequel == 1)

# subset of non-sequels
non_sequels <- subset(movies, sequel == 0)

5.) Comparing Critical/Audience Scores of Sequels and Non-Sequels

# The average critical score for sequels and non-sequels
acss <- mean(subset(movies, sequel == "Sequel")$critic_score)
acsn <- mean(subset(movies, sequel == "Non-Sequel")$critic_score)

# The average audience score for sequels and non-sequels
aass <- mean(subset(movies, sequel == "Sequel")$audience_score)
aasn <- mean(subset(movies, sequel == "Non-Sequel")$audience_score)

# Print the results
cat("Average Critical Score for Sequels:", acss)
## Average Critical Score for Sequels: 82
cat("Average Critical Score for Non-Sequels:", acsn)
## Average Critical Score for Non-Sequels: 79.75
cat("Average Audience Score for Sequels:", aass)
## Average Audience Score for Sequels: 92
cat("Average Audience Score for Non-Sequels:", aasn)
## Average Audience Score for Non-Sequels: 79.75

Non-sequels were on average a lower score than movies that are sequels.

6.) Two-By-Two Table

# Create a two-by-two table of sequel vs. superhero
sequel_superhero_table <- table(movies$sequel, movies$superhero)

# Print the table using kable for better formatting
kable(sequel_superhero_table, caption = "Two-By-Two Table: Sequel vs. Superhero")
Two-By-Two Table: Sequel vs. Superhero
No Yes
Non-Sequel 3 1
Sequel 1 2