Solved programming assignment 2 of the coursera R course