Skip to contents

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")

Arguments

data

A data frame to process.

exceptions

A character vector of column names to exclude from processing.

suffix

A string to append to renamed binary variables. Default is "_binary".

Value

A data frame with processed binary variables.

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!
#> ================================================================================