for the R Programming class on Coursera, week 4, programming assignment 3