Code for assignment 2, R data science course