R code for table 1 and 2