R code draft 2, first section done