My solution to homework 2 of R-Programming