R code I wrote for the Coursera Class