R script for Course Project