R code for the assignment