Question: This question is based on sakila database. You will also need the DBI and RMySQL packages, as well as the ggplot 2 package in R

This question is based on sakila database. You will also need the DBI and RMySQL packages, as well as the ggplot2 package in R.
a) Write a SQL Query to select payment_id, customer_id, rental_id, staff_id and amount from the payment table for all customers whose id is smaller than 15.
b) Load the results of this query into a data frame pDF in R using the dbGetQuery command (similar to what we did in class and assignments). Show the R-Code.
(While you need to create the connection string and run it in R, you need not show that code here; it is sufficient to show the R code for dbGetQuery ).
c) Display the top six rows of pDF using the head command. Show the R-Code and the Result.
d) Plot the histogram of the amount data. Show the R-Code and the Result.
e) Plot the histogram of amount using the customer_id as the facet. (Hint: Use the facet_wrap feature in ggplot). Show the R-Code and the Result.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!