product_vars: Retain values based on conditions

View source: R/scores_mh.R

product_varsR Documentation

Retain values based on conditions

Description

Creates new variables by applying conditions to specified columns (fork_vars) and retaining or modifying values from other columns (vars) based on keep_values. Generates new variables with ⁠_product⁠ suffix.

Usage

product_vars(data, fork_vars, vars, keep_values)

Arguments

data

A data frame containing the input data

fork_vars

Character vector of column names to use as logical conditions, evaluated against keep_values

vars

Character vector of column names whose values will be retained or modified based on conditions in fork_vars

keep_values

Vector of values in fork_vars to consider as "true" for retaining values in vars

Value

A data frame with new ⁠_product⁠ suffixed variables. Excludes intermediate logical columns.

Examples

product_vars(
  data = tibble::tibble(
    var_av = c("1", "2", "3", "4", "5", NA, "999", "777"),
    var_al = c("5", "4", "3", "2", "1", "777", NA, "999"),
    var_bv = c("1", "1", "36", "2", "1", NA, "999", "777"),
    var_bl = c("5", "2", "2", "2", "1", "777", NA, "999")
  ),
  fork_vars = c("var_al", "var_bl"),
  vars = c("var_av", "var_bv"),
  keep_values = "2"
)


ABCDscores documentation built on Sept. 11, 2025, 5:08 p.m.