Functions for R Peer Assignment 2