R code I found useful