solution for assignment 2 of Programming R