code for coursera R programming assignment 2