solution of the programming assignment 2 of the r programming course