Completed First Draft of R Code