finished R code file for course project