R Code used on Emily Malcolm's Blog