R code ready to answer both questions