Solution for R Programming - programming assignment 2