Assignment 2 from Programming in R