Here is modified .R file for the Assignemnt2