Completed functions for assignment

Added R file containing the example provided in the assignment description.