R programming assignment 2 function writing