HW3 R codes for problem 1a,b