R script for course project