Completed R file for Assignment 2