Binarize an input value based on a threshold

binarize(x, threshold = NULL, rep_na = NA, verbose = FALSE)

Arguments

x

numeric; A vector to binarize

threshold

numeric; The threshold for binarizing. Will default to the center number between max and min.

rep_na

numeric; The value to replace missing values with. Default NA.

verbose

boolean; flag for whether to display threshold or not

Value

vector; contains 0,1, if below or above the threshold, or 'rep.na' if NA

Details

Assigns a value of 0 or 1 based on being < or > the thresdhold, respectively. If x = threshold, x = 0. NA values are assigned as rep_na

Examples

vals <- c(0,0.25,0.5,0.75,1,NA) binarize(vals, threshold=0.5)
#> [1] 0 0 0 1 1 NA