Completed R file for Programming Assignment 2