Wrote a function for the Assignment

R function