binaryGrid | R Documentation |
Convert a real variable into a binary variable (i.e., 0 or 1) filtering by a threshold.
binaryGrid(
x,
condition = "GE",
threshold = NULL,
partial = FALSE,
ref.obs = NULL,
ref.pred = NULL,
values = c(0, 1),
simulate = FALSE
)
x |
The input grid to be converted to binary. It can be an object or a matrix/array. |
condition |
Inequality operator to be applied considering the given threshold.
|
threshold |
An integer. Threshold used as reference for the condition. Default is NULL. |
partial |
A logic value. If TRUE, only values that do not accomplish the condition will turn to 0 and the others will remain with their original grid real value. For example, if condition = "GT" and threshold = 1 then every value lower than 1 will turn to 0. 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 to binary the grid x. |
values |
A vector of length 2. For example, values = c(0,1), which is the DEFAULT. Then every sample satisfying the condition is equal to the second element of 'values' (i.e., in our example would be equal to 1), whereas if a sample does not satisfy the condition then takes the first element (i.e., in our example would be equal to 0). |
simulate |
A logical value. If TRUE then the output is an stochastic sample for given the probability of rain 'p'. Therefore only where the input grid 'x' is a grid of probabilities (e.g., for example coming from a logistic regression). |
The function works for regular and irregular grids as downloaded from loadeR).
A new grid object with binary values
J. Bano-Medina
require(climate4R.datasets)
data(VALUE_Iberia_pr)
# Take a look at the data:
head(VALUE_Iberia_pr$Data)
# Convert to complete binary variable:
ybin <- binaryGrid(VALUE_Iberia_pr,threshold = 1)
head(ybin$Data)
# Convert to partial binary variable:
ybin2 <- binaryGrid(VALUE_Iberia_pr,threshold = 1, partial = TRUE)
head(ybin2$Data)
# Convert to binary simulating:
dat <- gridArithmetics(ybin,0.5) # to build a dataset with probabilities
ybin3 <- binaryGrid(dat,simulate = TRUE)
head(ybin3$Data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.