Kinshella_HomeWork5

Load and merge the datasets

Make sure MoviesData.csv and MoviesStreaming.csv are saved in the same folder as this Quarto document before rendering it.

# Import the two CSV files
movies_data <- read.csv("MoviesData.csv", check.names = FALSE)
movies_streaming <- read.csv("MoviesStreaming.csv", check.names = FALSE)

# Merge the datasets using their shared ID column
movies <- merge(movies_data, movies_streaming, by = "ID")

# Display the first six rows of the merged dataset
head(movies)
  ID                             Title Year Age IMDb Rotten Tomatoes
1  1                         Inception 2010 13+  8.8              87
2  2                        The Matrix 1999 18+  8.7              87
3  3            Avengers: Infinity War 2018 13+  8.5              84
4  4                Back to the Future 1985  7+  8.5              96
5  5    The Good, the Bad and the Ugly 1966 18+  8.8              97
6  6 Spider-Man: Into the Spider-Verse 2018  7+  8.4              97
                                    Directors    Genres Runtime       Country
1                           Christopher Nolan    Action     148 United States
2              Lana Wachowski,Lilly Wachowski    Action     136 United States
3                     Anthony Russo,Joe Russo    Action     149 United States
4                             Robert Zemeckis Adventure     116 United States
5                                Sergio Leone   Western     161         Italy
6 Bob Persichetti,Peter Ramsey,Rodney Rothman Animation     117 United States
  Netflix Hulu Prime Video DisneyPlus
1       1    0           0          0
2       1    0           0          0
3       1    0           0          0
4       1    0           0          0
5       1    0           1          0
6       1    0           0          0

1. Merge two datasets by ID

The datasets are merged above using the ID column, which appears in both files.

dim(movies)
[1] 16744    14

2. Create separate histograms for IMDb and Rotten Tomatoes ratings

# Create the IMDb histogram
imdb_hist <- hist(movies$IMDb, plot = FALSE)

plot(
  imdb_hist,
  main = "Distribution of IMDb Ratings",
  xlab = "IMDb Rating",
  ylab = "Number of Movies",
  xlim = range(movies$IMDb, na.rm = TRUE),
  ylim = range(c(0, imdb_hist$counts)),
  col = "skyblue"
)

# Create the Rotten Tomatoes histogram
rt_hist <- hist(movies$`Rotten Tomatoes`, plot = FALSE)

plot(
  rt_hist,
  main = "Distribution of Rotten Tomatoes Ratings",
  xlab = "Rotten Tomatoes Rating",
  ylab = "Number of Movies",
  xlim = range(movies$`Rotten Tomatoes`, na.rm = TRUE),
  ylim = range(c(0, rt_hist$counts)),
  col = "salmon"
)

3. How many movies are in the Adventure genre?

adventure_count <- sum(movies$Genres == "Adventure", na.rm = TRUE)
adventure_count
[1] 606

4. Create a dataframe named movie_info with ID, Title, Year, and Runtime. Display its first six rows.

movie_info <- movies[, c("ID", "Title", "Year", "Runtime")]

head(movie_info)
  ID                             Title Year Runtime
1  1                         Inception 2010     148
2  2                        The Matrix 1999     136
3  3            Avengers: Infinity War 2018     149
4  4                Back to the Future 1985     116
5  5    The Good, the Bad and the Ugly 1966     161
6  6 Spider-Man: Into the Spider-Verse 2018     117

5. What is the average IMDb rating of all Drama movies?

drama_average <- mean(
  movies$IMDb[movies$Genres == "Drama"],
  na.rm = TRUE
)

drama_average
[1] 6.042693

6. What is the highest-rated IMDb Horror movie from 2015? Print only the movie title.

horror_2015 <- movies[
  movies$Genres == "Horror" & movies$Year == 2015,
]

highest_rated_horror <- horror_2015$Title[
  which.max(horror_2015$IMDb)
]

highest_rated_horror
[1] "Green Room"

7. How many movies are available on Netflix, Hulu, Prime Video, and Disney Plus?

cat("There are", sum(movies$Netflix == 1, na.rm = TRUE),
    "movies available on Netflix.\n")
There are 3560 movies available on Netflix.
cat("There are", sum(movies$Hulu == 1, na.rm = TRUE),
    "movies available on Hulu.\n")
There are 903 movies available on Hulu.
cat("There are", sum(movies$`Prime Video` == 1, na.rm = TRUE),
    "movies available on Prime Video.\n")
There are 12354 movies available on Prime Video.
cat("There are", sum(movies$DisneyPlus == 1, na.rm = TRUE),
    "movies available on Disney Plus.\n")
There are 564 movies available on Disney Plus.

8. How many movies are available via Disney Plus OR Prime Video?

The OR condition counts a movie if it is available on at least one of the two services. A movie available on both services is counted only once.

disney_or_prime <- sum(
  movies$DisneyPlus == 1 | movies$`Prime Video` == 1,
  na.rm = TRUE
)

disney_or_prime
[1] 12899