R functions from my blog rfunctions.blogspot.com