20141006: Updated R code for hw7