Functions for Assignment 2 of Coursera R Programmign Course