Updated R script for coursera