Coursera's R Programming assignment 2