Solution to programming assignment 2 in the Coursera course R Programming