R Programming - Assignment #2 implementation