| encode_bin_cat_vec | R Documentation |
In a character vector, converts binary categories to factor levels.
encode_bin_cat_vec(x, values = NULL, numeric_out = FALSE)
x |
non-numeric input vector |
values |
Optional named vector of user-defined values for binary values
using |
numeric_out |
If true, numeric vector is returned. If false, factor is returned. |
Before pair matching, mixed boolean encodings are normalised automatically.
If all unique non-missing values are boolean synonyms (e.g. a column
containing "false" and "true" recorded inconsistently as
"False" or "No"), they are collapsed to canonical
"false"/"true" so that the "false"="true" default pair
matches. The synonyms recognised are: "false", "FALSE",
"False", "no", "No", "NO", "n",
"N" (negative); and "true", "TRUE", "True",
"yes", "Yes", "YES", "y", "Y"
(positive). Note: numeric "0"/"1" are intentionally excluded
as they are ambiguous (e.g. "0" may represent a missing value);
handle these with strings_to_NA beforehand.
Binary categories to convert can be specified with a named character vector,
specified in values. The syntax of the named vector is:
negative_finding = positive_finding. If values is not
provided, the default list will be used: "No"="Yes",
"No/unknown"="Yes", "no/unknown"="Yes",
"Non-user"="User", "Never"="Ever", "WT"="MT",
"Male"="Female", "male"="female", "M"="F",
"m"="f", "FALSE"="TRUE", "false"="true",
"0"="1", "rural"="urban", "Absent"="Present",
"absent"="present", "Negative"="Positive",
"negative"="positive".
Factor with false finding encoded as 1 and true finding encoded as
2. Alternatively, numeric vector if numeric_out parameter is
TRUE.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.