Tag Archives: water year

Simple function in R to calculate water year

###########################################################################
# Simple Water Year Function
###########################################################################
wtr_yr <- function(dates, start_month = 10) {
# Convert possible character vector into date
d1 = as.Date(dates)
# Year offset
offset = ifelse(as.integer(format(d1, “%m”)) < start_month, 0, 1)
# Water year
adj.year = as.integer(format(d1, “%Y”)) + offset
# Return the water year
return(adj.year)
}

Leave a Comment

Filed under ScriptingMemo