Code for R Programming, assignment 3