create_from_rowsums.Rd
This function transforms selected columns in a dataframe to numeric, calculates their row-wise sums, and then creates a binary indicator column. The binary column is determined by whether the row sum is equal to or greater than 1. It dynamically generates the names for the row sum and binary columns based on input parameters.
create_from_rowsums(df, col_names, risk_behavior)
A modified dataframe with the original columns replaced by a binary indicator column, reflecting the presence (1) or absence (0) of the aggregated risk behavior, based on the sum of the specified columns.
The function performs the following steps:
Converts the specified columns (col_names) to numeric.
Calculates the row-wise sum of these columns, handling NA values.
Creates a binary indicator column (risk_behavior) where 1 indicates a row sum >= 1, and 0 indicates a row sum < 1.
Removes the original columns used for row sums, retaining only the binary indicator and other existing dataframe columns.