Make sure MoviesData.csv and MoviesStreaming.csv are saved in the same folder as this Quarto document before rendering it.
# Import the two CSV filesmovies_data <-read.csv("MoviesData.csv", check.names =FALSE)movies_streaming <-read.csv("MoviesStreaming.csv", check.names =FALSE)# Merge the datasets using their shared ID columnmovies <-merge(movies_data, movies_streaming, by ="ID")# Display the first six rows of the merged datasethead(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 histogramimdb_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 histogramrt_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")
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?