#install.packages("RMySQL")
library(RMySQL)
## Warning: package 'RMySQL' was built under R version 3.4.4
## Loading required package: DBI
## Warning: package 'DBI' was built under R version 3.4.4

Now to make the connection. With some tests to make sure the connection works.

movie_db = dbConnect(MySQL(), user='root', password='root', dbname='moviedb', host='localhost')
dbListTables(movie_db)
## [1] "movies"
dbListFields(movie_db, 'movies')
## [1] "id"            "first_name"    "black_panther" "avengers_iw"  
## [5] "incredible2"   "deadpool2"     "annihilation"  "mission_impo" 
## [9] "comments"

I sourced my data on Facebook using the movies( Black Panther,Avengers-Infinity War,Incredible2,Deadpool2,Annihilation,Mission_impossible). My friends are a mix of geeks and/or parents of young kids so I included movies likely to get a response. I recieved more then required by the assignment within minutes.

now to Read the database into the dataframe:

movie_df <- dbReadTable(movie_db, name = "movies")
movie_df <- data.frame(movie_df)
movie_df
##   id first_name black_panther avengers_iw incredible2 deadpool2
## 1  1     Felipe           0.0         0.0         0.0         2
## 2  2    Suvarna           4.0         5.0         4.0         0
## 3  3      Pavan           5.0         5.0         5.0         0
## 4  4     Jayesh           4.0         4.0         4.0         2
## 5  5    Charles           4.0         4.0         5.0         2
## 6  6      Robbi           3.5         3.5         4.5         2
## 7  7    Pradeep           0.0         0.0         5.0         3
## 8  8       Lisa           4.0         5.0         5.0         0
##   annihilation mission_impo                          comments
## 1          3.0          0.0                              None
## 2          4.0          5.0                              None
## 3          0.0          5.0                              None
## 4          2.0          5.0                   Fantastic Movie
## 5          0.0          3.0 Incredible2, liked it quite a bit
## 6          1.5          3.5                              None
## 7          2.0          5.0                              None
## 8          3.0          5.0                              None

While we are at it let’s take a look at the data, keeping in mind that 0 means they did not see the film. Since I did have friends that insisted in half scores, histograms work a little better than bar plots in R even though the data is still discrete.

hist(movie_df$black_panther)

hist(movie_df$avengers_iw)

hist(movie_df$incredible2)

hist(movie_df$deadpool2)

hist(movie_df$annihilation)

hist(movie_df$mission_impo)

Conclusion:

It looks like Incredible2 was the most liked movie with Mission Impossible coming in a close second, Deadpool2 was the least liked an annihilation had the most spread in opinion.