Introduction

This week’s assignment requires creation of a table with reviews of five movies from friends and family in MySQL, read and analyzed in R. I chose children’s movies because with two little girls these are practically the only movies I have seen in the past four years. And I surveyed six friends and family who similarly are familiar with these animated features. I then used multiple analysis functions to display and analyze the data to see if any trends emerged.

Load library

library(RMySQL)  
## Loading required package: DBI

Connect to MySQL server

mysqlconnection = dbConnect(MySQL(),user='root',password=password1,dbname='movies_db',host='localhost')  

Read the table in the movies_db database

result = dbSendQuery(mysqlconnection,"select * from movie_reviews")

Create a new data frame from the MySQL table

moviereview_df=fetch(result,n=6)  

Display the table

print(moviereview_df)  
##   Reviewer_ID Reviewer_Name Moana The_Incredibles Epic Lego_Movie Up
## 1           1     Christina     4               6    3          5  5
## 2           2        Vivian     5               4    4          4  5
## 3           3         James     4               4    3          3  4
## 4           4          Jill     5               4    3          1  5
## 5           5       Grandma     5               4    2          2  5
## 6           6       Grandpa     4               4    2          2  5
##   Wall-E
## 1      5
## 2      3
## 3      4
## 4      5
## 5      3
## 6      3

Analyze the reviews: create a new data frame with the average score for each movie

averagescore <- colMeans(moviereview_df[,3:8])  
print(averagescore)  
##           Moana The_Incredibles            Epic      Lego_Movie 
##        4.500000        4.333333        2.833333        2.833333 
##              Up          Wall-E 
##        4.833333        3.833333