R code for MAT013 and various other stuff