give me solution for question 2 only in my problem set r code required

please Write clearly and show details for each steps. Thank you. No extension deadline.

For R code, paste the code with its output in a Pdf file. No extension for the deadline.