convert2bin: Convert grid values to a binary variable

View source: R/convert2bin.R

convert2binR Documentation

Convert grid values to a binary variable

Description

Convert a real variable into a binary variable (i.e., 0 or 1) filtering by a threshold.

Usage

convert2bin(
  x,
  threshold = NULL,
  partial = FALSE,
  ref.obs = NULL,
  ref.pred = NULL
)

Arguments

x

The input grid to be converted to binary. It can be an object or a matrix/array.

threshold

Upon or equal the threshold the grid values turn to 1, whereas below it turns to 0. This can be a single value or a vector. In case it is a vector it will apply a different threshold on each station. If threshold is NULL, then the data is converted to binary by a value that makes the ref.pred to have the same number of 0 values than those in the ref.obs. Default is NULL.

partial

If TRUE, only values below the threshold will turn to 0 and the others will remain with their original grid real value. Default is FALSE.

ref.obs

Grid of observations. It is used to determine the number of days where there is no event (or value equal to 0).

ref.pred

Grid of predictions. It is used to calculate the threshold that will further be used to convert the grid x to binary.

Details

The function only works for a vector of observations/predictands downloaded from loadeR).

Value

A new grid object with binary values

Author(s)

J. Bano-Medina

See Also

Other downscaling.helpers: filterNA(), makeMultiGrid()

Examples


require(climate4R.datasets)
data(VALUE_Iberia_pr)
# Take a look at the data:
require(climate4R.datasets)
data("VALUE_Iberia_pr")
head(VALUE_Iberia_pr$Data)
# Convert to complete binary variable:
ybin <- convert2bin(VALUE_Iberia_pr,threshold = 1)
head(ybin$Data)
# Convert to partial binary variable:
ybin2 <- convert2bin(VALUE_Iberia_pr, threshold = 1, partial = TRUE)
head(ybin2$Data)


SantanderMetGroup/transformeR documentation built on Oct. 28, 2023, 5:26 a.m.