| is_binary | R Documentation |
Tests whether a variable contains only the values 0 and 1.
is_binary(data = NULL, dependent.variable.name = NULL)
data |
Data frame containing the variable to check. |
dependent.variable.name |
Character string with the name of the variable to test. Must be a column name in |
This function is used internally by spatialRF to determine whether to apply classification-specific methods (e.g., case weighting with case_weights()). The function returns FALSE if:
The variable has more than two unique values
The variable has only one unique value (constant)
The unique values are not exactly 0 and 1 (e.g., 1 and 2, or TRUE and FALSE)
Missing values (NA) are ignored when determining unique values.
Logical. TRUE if the variable contains exactly two unique values (0 and 1), FALSE otherwise.
case_weights()
Other preprocessing:
auto_cor(),
auto_vif(),
case_weights(),
default_distance_thresholds(),
double_center_distance_matrix(),
make_spatial_fold(),
make_spatial_folds(),
the_feature_engineer(),
weights_from_distance_matrix()
# Binary variable (returns TRUE)
is_binary(
data = data.frame(response = c(0, 0, 0, 1, 1)),
dependent.variable.name = "response"
)
# Non-binary variable (returns FALSE)
is_binary(
data = data.frame(response = c(1, 2, 3, 4, 5)),
dependent.variable.name = "response"
)
# Binary but wrong values (returns FALSE)
is_binary(
data = data.frame(response = c(1, 1, 2, 2)),
dependent.variable.name = "response"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.