R Programming: Programming assignment 2