binaryGrid: Convert grid values to a binary variable

Description Usage Arguments Details Value Author(s) Examples

View source: R/binaryGrid.R

Description

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

Usage

1
2
binaryGrid(x, condition = "GE", threshold = NULL, partial = FALSE,
  ref.obs = NULL, ref.pred = NULL, values = c(0, 1))

Arguments

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. "GT" = greater than the value of threshold, "GE" = greater or equal, "LT" = lower than, "LE" = lower or equal than. Values that accomplish the condition turn to 1 whereas the others turn to 0.

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).

Details

The function works for regular and irregular grids as downloaded from loadeR).

Value

A new grid object with binary values

Author(s)

J. Bano-Medina

Examples

1
2
3
4
5
6
7
8
# 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)

SantanderMetGroup/transformeR documentation built on Nov. 23, 2019, 12:28 p.m.