R assignment 2

The functions for assignment2