edited R script for assignment 2