Completion of majority of R code for Rmd document