Code from the r tutorial on my blog