R code - Handy routines for hydrologists


What is R?

R is an open source programming language and environment for data analysis. It has rich functionality for data processing, analysis and graphing. See the R home page for more information and to download the package. Be forewarned that R has a steep learning curve. However, once you gain proficiency in R, the time invested in learning R will be paid back many times over.


R and hydrology

Data analysis is an integral part of hydrology. Hydrologists frequently use techniques, such as regression analysis, which are incorporated into conventional statistical packages and spreadsheet software. However, many hydrological analyses are not, including intensity-duration-frequency analysis and flood frequency analysis. These analyses are relatively simple to code in R.


R primers


R scripts for specific hydrologic analyses

What I have included here are bits of R code that hydrologists may find useful. If you have written some code that you would like to share, please send it along and I'll consider posting it here.

You are free to use, distribute and modify the code below. If you do so, please send me an email to let me know which scripts you have used.

Disclaimer I am an old dog who generally avoids learning new tricks. I began my programming career with WATFIV and punch cards and then progressed through FORTRAN 77, Turbo Pascal and Fortran 90/95 before discovering R, which satisfies all of my current programming/data analysis requirements. Most of my code uses base R with the more recent scripts using a smattering of TidyVerse packages. However, I persist in using base and Lattice graphics. I have tried ggplot, which is great for exploratory analysis of multivariate relations in a data set. However, I find it bothersome to use it to generate highly customized figures for publication.