unzero: Remove precipitation zeros by setting them to NA

Description Usage Arguments Details Examples

View source: R/unzero.R

Description

unzero eliminates zero precipitation data from the bias correction by setting zero values to NA, which is ignored. rezero sets NA values back to zero after bias correction.

Usage

1
2
3
unzero(x, warn=FALSE)

rezero(x, refloor=TRUE)

Arguments

x

A vector of numeric values

warn

Logical; warn if NA values already present in input

refloor

Logical; also set negative values to zero

Details

The zeros in precipitation data cause problems for distribution mapping. Changing zeros to NA allows them to pass harmlessly through the rest of the bias correction procedure without requiring a lot of complicated and error-prone indexing to remove and reinsert them from the arrays.

It is not uncommon for precipitation data to have small negative values after bias correction. By default rezero also sets those values to zero when returning NA values back to zero.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
set.seed(22)

x <- rbinom(10, 2, 0.2)
y <- unzero(x)
x
y
rezero(y)
z <- unzero(c(x, NA, NA), warn=TRUE)
z <- c(z, -1)
z
rezero(z, refloor=FALSE)

sethmcg/climod documentation built on Nov. 19, 2021, 11:12 p.m.