Description Usage Arguments Details Examples
Conditionally transforms a non-boolean vector into a boolean vector
1 |
x |
A non-boolean vector |
true |
A condition in which to evaluate as TRUE |
false |
An optional condition to evaluate as FALSE |
na |
An optional condition to evaluate as NA. If 'na' is set, so must either 'true' or 'false'. |
names |
Logical. If TRUE, the result will print out with a name |
If the 'class()' of 'true', 'false', or 'na' is 'function', the function will be applied to the vector 'x' and when evaluated as 'TRUE' will return the respective value of the argument. A warning will appear when 'true', 'false', and 'na' are all set together. Only two should be set at a time as any value that has not been matched will default to the unused argument.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | x <- c("Y", "Y", "N", "Y", "N", "N/A", "Y - not sure", "YN", "YY")
to_boolean(x, "Y")
to_boolean(x, "Y", names = TRUE)
to_boolean(x, "Y", "N", names = TRUE)
to_boolean(x,
true = function(x) grepl("^Y", x),
na = "N/A",
names = TRUE)
x <- sample(c("Yes", "Maybe", "No", "??"), 10, TRUE)
to_boolean(x, c("Yes", "Maybe"), "No", names = TRUE)
x <- c(1, 2, 3, 4)
to_boolean(x, 1, 2)
to_boolean(x, "<= 1", ">= 3")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.