Process Binary Variables in a Data Frame
Source:R/margot_process_binary_vars.R
margot_process_binary_vars.Rd
This function identifies binary variables (both factors and numeric), converts them to 0/1 format, and renames them. It allows for exceptions to be specified.
Usage
margot_process_binary_vars(data, exceptions = character(0), suffix = "_binary")
Examples
df <- data.frame(
a = factor(c("yes", "no", "yes")),
b = c(1, 0, 1),
c = c("apple", "banana", "apple"),
d = factor(c("true", "false", "true"))
)
processed_df <- margot_process_binary_vars(df, exceptions = "c")
#>
#> === Processing Binary Variables ===
#>
#> Initial Data Summary:
#> Total variables: 4
#> Total observations: 3
#> Exceptions specified: 1
#>
#> Binary Variables Identified:
#> Total binary variables: 3
#> List of binary variables:
#>
#>
#> |Variable |
#> |:--------|
#> |a |
#> |b |
#> |d |
#>
#> Variable Renaming:
#>
#>
#> |Original |New |
#> |:--------|:--------|
#> |a |a_binary |
#> |b |b_binary |
#> |d |d_binary |
#>
#> Final Data Summary:
#> Total variables: 4
#> Variables processed: 3
#> Variables excluded: 1
#>
#> Binary variable processing completed successfully!
#> ================================================================================