create_recode: Instruction set for recoding

View source: R/create_recode.R

create_recodeR Documentation

Instruction set for recoding

Description

Creates/standardizes the parameters required for recoding a variable.

Usage

create_recode(
  old_var,
  new_var,
  old = NULL,
  new = NULL,
  new_label = NULL,
  simplify_to_numeric = TRUE
)

Arguments

old_var

character. Column in the dataset containing the values to be recoded

new_var

character. Column where the recoded values will be placed. If new_var doesn't exist, than it will be created. Otherwise it will be overwritten.

old

character (or coercible). value in the column old_var to be translated into a new value by recoding. If left blank/NA/""/NULL or otherwise missing, the recode operation will essentially take the form of a rename of old_var -> new_var. Except for renaming type situations, nothing of old_var is kept (e.g. all relevant values must have a recode row)

new

character (or coercible). Column indicating where the new values for the recoding process exist. It is positionally (e.g. row) tied to a particular old. If blank, it helps identify a simpler rename operation.

new_label

character (or convertable to character). The factor label that old will be recoded to in conjunction with the position of new

simplify_to_numeric

logical. Converts old and new into numerics if it can be done loselessly. Otherwise, a warning will be thrown.

Details

This function mostly exists to help translate (via parse_recode_instructions) data.frame type read-ins of recoding into a standardized form. These results can then be passed to enact_recoding as part of a bulk recoding process.

Value

a list of lists (of class recode_instruction).


PHSKC-APDE/rads documentation built on April 14, 2025, 10:47 a.m.