convert2factor.Rd
This function automatically detects and converts binary variables (with exactly two unique non-NA values) in a data frame to factors. Currently only supports conversion from binary variables.
convert2factor(data, from = "binary")
A data frame containing variables to be converted.
Type of variables to convert. Currently only supports "binary" (default).
The original data frame with binary variables converted to factors. The function preserves existing factor variables and skips non-binary columns.
df <- data.frame(a = c(0,1,0), b = c("Y","N","Y"))
converted_df <- convert2factor(df)
#> ℹ a has been converted to a factor: 0, 1
#> ℹ b has been converted to a factor: N, Y