Coursera R Programming : Programming Assignment 2, my implementation