#' Function to return the DL5 hydrologic indicator statistic for a given data frame
#'
#' This function accepts a data frame that contains a column named "discharge" and
#' calculates the mean of the annual minimum 90-day average flows for the entire record
#'
#' @param qfiletempf data frame containing a "discharge" column containing daily flow values
#' @param pref string containing a "mean" or "median" preference
#' @return dl5 numeric containing the mean of the annual minimum 90-day average flows for the given data frame
#' @export
#' @examples
#' load_data<-paste(system.file(package="HITHATStats"),"/data/obs_data.csv",sep="")
#' qfiletempf<-read.csv(load_data)
#' dl5(qfiletempf)
dl5 <- function(qfiletempf, pref = "mean") {
day90mean <- rollmean(qfiletempf$discharge, 90, align = "right",
na.pad = TRUE)
day90rollingavg <- data.frame(qfiletempf, day90mean)
rollingavgs90day <- subset(day90rollingavg, day90rollingavg$day90mean !=
"NA")
min90daybyyear <- aggregate(rollingavgs90day$day90mean,
list(rollingavgs90day$wy_val), min, na.rm=TRUE)
if (pref == "median") {
dl5 <- median(min90daybyyear$x)
}
else {
dl5 <- mean(min90daybyyear$x)
}
return(dl5)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.