Code solution for 'R Programming' Assignment 2