update of R code in Programming Assignment 2