onezero | R Documentation |
Converts a vector into ones and zeroes, any values which fall outside of what
is set by the arguments gets converted to missing. Option to retain missing
values if nothing is passed to zero
.
onezero(x, one_values, zero_values, one_threshold, keep.na = TRUE)
x |
A vector. |
one_values |
Vector of values in |
zero_values |
Vector of values in |
one_threshold |
Character string describing threshold for determining 1/0. Must follow
a logical-operator-then-value format, using <, <=, >, >=, ==, or !=. Cannot be used in combination
with |
keep.na |
Only needed if |
A numeric vector of ones and zeros.
is_onezero()
x <- c("one", "zero", "foo", NA)
y <- 1:4
onezero(x, one_values = "one")
onezero(x, one_values = "one", keep.na = FALSE)
onezero(x, one_values = "one", zero_values = "zero")
onezero(x, one_values = "one", zero_values = c("zero", "foo"))
onezero(x, one_values = "bar")
onezero(x, one_values = "bar", keep.na = FALSE)
onezero(x, one_values = "bar", zero_values = "baz")
onezero(y, one_threshold = "<= 2")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.