Importing from github
This imports data from github.
url <- "https://raw.githubusercontent.com/Osama-Siddiqui/DATA607-A2-MovieRatings/refs/heads/main/movie_ratings.csv"
movie_ratings <- read.csv (url, na.strings = c ("" , "NULL" , "NA" ))
head (movie_ratings)
user_id user_name movie_id
1 1 Hala 1
2 1 Hala 2
3 1 Hala 3
4 1 Hala 4
5 1 Hala 5
6 1 Hala 6
movie_title release_year
1 Oppenheimer 2023
2 Demon Slayer: Kimetsu no Yaiba – The Movie: Infinity Castle 2025
3 Sinners 2025
4 Superman 2025
5 SpiderMan: Brand New Day 2026
6 The Odyssey 2026
rating
1 4
2 3
3 4
4 4
5 NA
6 NA
Test and see the sample data in the tables.
'data.frame': 30 obs. of 6 variables:
$ user_id : int 1 1 1 1 1 1 2 2 2 2 ...
$ user_name : chr "Hala" "Hala" "Hala" "Hala" ...
$ movie_id : int 1 2 3 4 5 6 1 2 3 4 ...
$ movie_title : chr "Oppenheimer" "Demon Slayer: Kimetsu no Yaiba – The Movie: Infinity Castle" "Sinners" "Superman" ...
$ release_year: int 2023 2025 2025 2025 2026 2026 2023 2025 2025 2025 ...
$ rating : int 4 3 4 4 NA NA 4 4 5 4 ...
user_id user_name movie_id movie_title release_year
Min. :1 Length :30 Min. :1.0 Length :30 Min. :2023
1st Qu.:2 N.unique : 5 1st Qu.:2.0 N.unique : 6 1st Qu.:2025
Median :3 N.blank : 0 Median :3.5 N.blank : 0 Median :2025
Mean :3 Min.nchar: 4 Mean :3.5 Min.nchar: 7 Mean :2025
3rd Qu.:4 Max.nchar: 7 3rd Qu.:5.0 Max.nchar:59 3rd Qu.:2026
Max. :5 Max. :6.0 Max. :2026
rating
Min. :3.000
1st Qu.:4.000
Median :4.000
Mean :4.222
3rd Qu.:5.000
Max. :5.000
NAs :3
How many rating were n/a (reviewer did not watch)
sum (is.na (movie_ratings$ rating))
What percent of movies were not watched
total_ratings <- nrow (movie_ratings)
missing_ratings <- sum (is.na (movie_ratings$ rating))
missing_percentage <- missing_ratings / total_ratings * 100
missing_percentage
Below is an Avg of the movie rating, but this ignores the N/A
movie_summary <- aggregate (
rating ~ movie_title,
data = movie_ratings,
FUN = mean
)
movie_summary$ rating <- round (movie_summary$ rating, 2 )
movie_summary
movie_title rating
1 Demon Slayer: Kimetsu no Yaiba – The Movie: Infinity Castle 3.80
2 Oppenheimer 4.40
3 Sinners 4.60
4 SpiderMan: Brand New Day 3.75
5 Superman 4.00
6 The Odyssey 5.00
This orders the movies by ratings (n/a still not applicable)
movie_summary <- movie_summary[
order (- movie_summary$ rating),
]
movie_summary
movie_title rating
6 The Odyssey 5.00
3 Sinners 4.60
2 Oppenheimer 4.40
5 Superman 4.00
1 Demon Slayer: Kimetsu no Yaiba – The Movie: Infinity Castle 3.80
4 SpiderMan: Brand New Day 3.75
Number if rating per movie (how many movies were watched and where the n/a was applied)
rating_count <- aggregate (
rating ~ movie_title,
data = movie_ratings,
FUN = length
)
names (rating_count)[2 ] <- "rating_count"
rating_count
movie_title rating_count
1 Demon Slayer: Kimetsu no Yaiba – The Movie: Infinity Castle 5
2 Oppenheimer 5
3 Sinners 5
4 SpiderMan: Brand New Day 4
5 Superman 5
6 The Odyssey 3
This is the full data
final_summary <- merge (
movie_summary,
rating_count,
by = "movie_title"
)
final_summary <- final_summary[
order (- final_summary$ rating),
]
final_summary
movie_title rating
6 The Odyssey 5.00
3 Sinners 4.60
2 Oppenheimer 4.40
5 Superman 4.00
1 Demon Slayer: Kimetsu no Yaiba – The Movie: Infinity Castle 3.80
4 SpiderMan: Brand New Day 3.75
rating_count
6 3
3 5
2 5
5 5
1 5
4 4
Movie ratings Visualization
library (ggplot2)
ggplot (final_summary,
aes (x = reorder (movie_title, rating),
y = rating)) +
geom_col (fill = "steelblue" ) +
geom_text (aes (label = rating), hjust = - 0.1 ) +
coord_flip () +
ylim (0 , 5.5 ) +
labs (
title = "Average Movie Ratings" ,
x = "Movie" ,
y = "Average Rating"
) +
theme_minimal ()
Conclusion
For this assignment, I used PostgreSQL to store movie ratings and R to analyze the collected data. Out of 30 possible ratings, 27 were provided, with 10% of the data missing. The Odyssey received the highest average rating, followed by Sinners. However, The Odyssey received fewer ratings than most of the other movies. I excluded missing values from the calculations rather than assigning them a rating. This assignment demonstrates how SQL and R can be used together to store, retrieve, and analyze data.
Acknowledgments and AI Disclosure
ChatGPT (OpenAI) was used as a supplemental resource for R coding assistance, troubleshooting, and document organization.