Convert a Boolean Matrix to charsets (character set representation).
Arguments
- df
A data frame containing the Boolean matrix to be converted.
- setvar
A character string specifying the variable name prefix for the columns of the Boolean matrix in the input data frame.
- cname
A character string specifying the name of the new column to be added to the output data frame. If NULL, the value of 'setvar' will be used as the column name. Default is NULL.
- drop_set
A logical value indicating whether to drop the original columns of the Boolean matrix from the output data frame. Default is FALSE.
Details
This function takes a Boolean matrix and converts it to a string representation. Each row of the matrix is represented as a set enclosed in curly braces. The resulting string representation is added as a new column to the input data frame.
Examples
# Create a sample data frame with a Boolean matrix
df <- data.frame(x1 = c(TRUE, FALSE, TRUE), x2 = c(FALSE, TRUE, FALSE))
# Convert the Boolean matrix to string representation
result <- md_boolean_matrix_to_charsets(df, setvar = "x", cname = "X")
print(result)
#> x1 x2 X
#> 1 TRUE FALSE {1}
#> 2 FALSE TRUE {2}
#> 3 TRUE FALSE {1}