How To Write Functions In R Programming? Convert Code To Function