r code for PA#2