R programming: Programming assignment, Week 3