Install pgAdmin4 and create database to analyse movies and their ratings.
PgAdmin4
I inputted data into my database I created in pgAdmin4. I inserted tables for user, movies and ratings.
library(DBI) library(RPostgres) 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
library(tidyr)
Connect to the database
I connect to the database below. I figured out how to add it and hide my password. I used Gemini to help me figure out how to do that in Rstudio.
con <-dbConnect( RPostgres::Postgres(),dbname ="MoviesCCB",host ="localhost",port =5432,user ="postgres",password =Sys.getenv("DB_PASSWORD"))
Fetch data frames
ratings <-dbGetQuery(con, " SELECT u.user_name, m.movie_title, r.rating_value FROM Ratings r JOIN Users u ON r.user_id = u.user_id JOIN Movies m ON r.movie_id = m.movie_id;")
# A tibble: 2 × 5
user_name movie_title user_id movie_id rating_value
<chr> <chr> <int> <int> <int>
1 Ashley The Drama NA NA NA
2 Charles Odyssey NA NA NA
# A tibble: 5 × 3
user_name movies_watched average_score
<chr> <int> <dbl>
1 Ashley 4 3.75
2 Charles 4 4
3 Jennifer 5 4.2
4 Jordi 5 3.8
5 Kevin 5 4
Conclusion
From my data, the movie with the highest average rating was Spiderman: Brand New Day. The second highest average rated movie is a tie between The Drama and Odyssey. Spiderman was the highest rated and all 5 friends had seen the movie.