Coursera R exercise 3