Skip to contents

This function replaces binary columns (which correspond to choices) with NA for a specified subset of the data. It is typically used when expanding top priority columns into child binary columns, ensuring that child columns for choices that do not apply to a subset are set to NA.

Usage

replace_na_subset(
  data,
  subset_col,
  subset_value,
  sep = ".",
  col_parent,
  choice_vals
)

Arguments

data

A data.table or data.frame: The data to be processed.

subset_col

A character vector: The name of the column that defines the subset.

subset_value

A character vector: The value in subset_col for which binary columns will be replaced with NA.

sep

A character vector: The separator used in the child binary column names (default is ".").

col_parent

A character vector: The name of the parent column (usually the question) that defines child binary columns.

choice_vals

A character vector: The values corresponding to the child binary columns that should be replaced with NA.

Value

A data.table or data.frame with the binary columns replaced by NA for the relevant subset.