completed R code for the assignment