Skip to contents

Converts a string vector to a numeric vector according to the following:

  1. Elements exactly matching any value in missing return NA.

  2. Otherwise, elements matching any fixed pattern in pattern return 1.

  3. All other elements return 0.

Usage

OR.string.to.binary(input, pattern, missing)

Arguments

input

String vector to evaluate.

pattern

String vector of fixed patterns to each within input.

missing

String vector of exact values to treat as NA.

Value

Numeric vector of 1 (pattern matched), 0 (no match), or NA (missing).

See also

Examples

print(OR.string.to.binary(c("Yes", "Yes*", "No", "Missing"), "Yes", "Missing"))
#> [1]  1  1  0 NA