to_logical {batman} | R Documentation |
Convert categorical representations of true/false values to a logical
Description
to_logical
is designed for the situation where you have categorical data
(perhaps from a survey, or direct user input) that represents TRUE/FALSE values as something
other than TRUE/FALSE - "Yes", "No", "None", "Y" or "False", say. With to_logical
you can easily convert a vector of these values into an actual, logical vector, using
either a predefined set of accepted TRUE or FALSE equivalents, or a set you specify
yourself.
Usage
to_logical(x, language = "en", custom_true = character(),
custom_false = character())
Arguments
x |
a vector of categorical TRUE/FALSE/NA values. |
language |
the language to use. See |
custom_true |
a vector of values to consider, in addition to the ones
|
custom_false |
a vector of values to consider, in addition to the ones
|
Examples
# A very simple example using the pre-known true and false equivalents
categorical_values <- c("true","t","y","yes","f","no","1")
to_logical(categorical_values)
# Use a custom specifier
categorical_values <- c("NA","NA","NA","NA","NA","NA","NA","NA","Batman")
to_logical(categorical_values, custom_true = c("Batman"))