Updated R code and rmd