Completed R file for assignment 2