R code for Assignment 1