R code to run course project, not completely finished version 2