#' Assigns NA to values that match a quality check flag threshold. For example, if the user specifies 'flag = c(2:3)', this function will assign NAs to any rows where the qc flag is either 2 or 3.
#' @export
#' @title Assign NA to bad flags
#' @param y a numeric vector of data.
#' @param qc_col a numeric vector containing qc flag values (0 = measured, 1 = good gapfill, 2 = okay gapfill, 3 = poor gapfill).
#' @param flag a user-specified qc threshold. All data that match this qc threshold are assigned a value of NA. If no qc value is available, the original data are retained.
# It first evaluates whether flags are actually available. If no data quality flags are available (all NAs), the original site data is retained.
# IF flags are found, it looks for flags are equal to the specified flag threshold (e.g. 3 = 'bad' gapfill) and assigns a value of NA to the corresponding data.
fCheckforQCFlags <- function(y, qc_col, flag) {
# small function that assigns a value of -9999 to NAs. (Allows for logical comparisons with NA objects)
fCheckNA <- function(x) {
ifelse(is.na(x), -9999, x)
}
if (all(is.na(qc_col))) {
y
} else {
ifelse(fCheckNA(qc_col) %in% flag, NA, y)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.