added some R functions from Coursera's course