update the R code for Assign 2