Modified r code for Assignment2