R code to run course project, version 3