This function sums the number of times a set of values (vals) appears across a set of variables (vars) in a data frame into a new variable (new_var).
Usage
sum_vals_across(df, vars, vals, new_var)
Arguments
- df
A data frame to modify.
- vars
A character vector of variables.
- vals
A character vector of values.
- suffix
A character scalar or an empty string to append to the variable names. Defaults to NULL.
Value
The modified data frame with undefined values replaced by NA. If suffix is NULL or an empty string, variables vars are modified; otherwise, new variables are added with suffix.