Useful R code for data analysis