Solution for assignment 2 of the R coursera course