My solution to R Programming assignment #2