Commit 6dab9d39 authored by Dorchies David's avatar Dorchies David
Browse files

fix(calcQA): error in SeriesAggreg

Refs #5
parent 41bfcd4c
Pipeline #31740 failed with stages
in 12 minutes and 18 seconds
......@@ -40,6 +40,8 @@ export(loadCalibrationParams)
export(loadConfig)
export(loadHydratecDB)
export(loadHypsoData)
export(mean_na_rm)
export(not_na_count)
export(readDrias2020)
export(readQsim)
export(saveFlowDB)
......
......@@ -23,18 +23,38 @@ calcQA <- function(x, threshold = 0.2, ...) {
#' @export
#' @rdname calcQA
calcQA.data.frame <- function(x, threshold = 0.2, ...) {
QA <- SeriesAggreg(x, Format = "%Y", rep("mean.na.rm", ncol(x)-1))
nDaysNotNA <- SeriesAggreg(x, Format = "%Y", rep("not_na.count", ncol(x)-1))
QA <- SeriesAggreg(x, Format = "%Y", rep("mean_na_rm", ncol(x)-1))
nDaysNotNA <- SeriesAggreg(x, Format = "%Y", rep("not_na_count", ncol(x)-1))
QA <- QA[, -1]
nDaysNotNA <- nDaysNotNA[, -1]
QA[nDaysNotNA < threshold * 365] <- NA
apply(QA, 2, mean.na.rm)
apply(QA, 2, mean_na_rm)
}
not_na.count <- function(x) {
#' Count non-NA values in an object
#'
#' @param x the object where to count available values
#'
#' @return The number of non-NA values
#' @export
#'
#' @examples
#' not_na.count(c(1, 2, 3, NA, 4))
#'
not_na_count <- function(x) {
sum(!is.na(x))
}
mean.na.rm <- function(x) {
#' Arithmetic Mean with NA stripped before computation
#'
#' @param x An R object.
#'
#' @return See [mean]
#' @export
#'
#' @examples
#' mean.na.rm(c(1, 2, 3, NA, 4))
#'
mean_na_rm <- function(x) {
mean(x, na.rm = TRUE)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/meanQ.R
% Please edit documentation in R/calcQA.R
\name{calcQA}
\alias{calcQA}
\alias{calcQA.data.frame}
......@@ -8,13 +8,15 @@
Chazot, Sébastien, Perrin, Charles, Jean-Philippe Vidal, Eric Sauquet, Mathilde Chauveau, et Nathalie Rouchy. 2012. « Explore 2070 - Lot Hydrologie de surface - A2 - Résultats : Fiches, Cartes et Graphes ». Ministère de l’écologie, du développement durable, des transports et du logement.
}
\usage{
calcQA(x, ...)
calcQA(x, threshold = 0.2, ...)
\method{calcQA}{data.frame}(x, ...)
\method{calcQA}{data.frame}(x, threshold = 0.2, ...)
}
\arguments{
\item{x}{a \link{data.frame} with a first column containing dates in \link{POSIXt} format and one \link{numeric} column per gauging station}
\item{threshold}{\link{numeric} minimum ratio of available data in a year to take it into account}
\item{...}{Use for S3 method compatibility}
}
\value{
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/calcQA.R
\name{mean_na_rm}
\alias{mean_na_rm}
\title{Arithmetic Mean with NA stripped before computation}
\usage{
mean_na_rm(x)
}
\arguments{
\item{x}{An R object.}
}
\value{
See \link{mean}
}
\description{
Arithmetic Mean with NA stripped before computation
}
\examples{
mean.na.rm(c(1, 2, 3, NA, 4))
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/calcQA.R
\name{not_na_count}
\alias{not_na_count}
\title{Count non-NA values in an object}
\usage{
not_na_count(x)
}
\arguments{
\item{x}{the object where to count available values}
}
\value{
The number of non-NA values
}
\description{
Count non-NA values in an object
}
\examples{
not_na.count(c(1, 2, 3, NA, 4))
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment