Finish Editing 1st version of R code