Completed R script for Programming Assignment2