Final R code for Programming Assignment 2