#' Function to return the DL3 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 7-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 dl3 numeric containing the mean of the annual minimum 7-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)
#' dl3(qfiletempf)
dl3 <- function(qfiletempf, pref = "mean") {
day7mean <- rollmean(qfiletempf$discharge, 7, align = "right",
na.pad = TRUE)
day7rollingavg <- data.frame(qfiletempf, day7mean)
rollingavgs7day <- subset(day7rollingavg, day7rollingavg$day7mean !=
"NA")
min7daybyyear <- aggregate(rollingavgs7day$day7mean,
list(rollingavgs7day$wy_val), min, na.rm=TRUE)
if (pref == "median") {
dl3 <- median(min7daybyyear$x)
}
else {
dl3 <- mean(min7daybyyear$x)
}
return(dl3)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.