r code commited after writing my own functions

for prog assignment 2