Select and Rename Columns Based on Criteria
Source:R/select_and_rename_cols.R
select_and_rename_cols.Rd
Selects columns from a base set that match specified baseline variables and renames an outcome variable by changing its prefix. Useful for longitudinal data where time-point prefixes need to be standardised or adjusted.
Usage
select_and_rename_cols(
names_base,
baseline_vars,
outcome,
from_prefix = "t2",
to_prefix = "t0"
)
Arguments
- names_base
a character vector of column names from which to select.
- baseline_vars
a character vector of baseline variables to match in `names_base`.
- outcome
the name of the outcome variable whose prefix should be replaced.
- from_prefix
the original prefix of the outcome variable to be replaced, defaulting to "t2". the prefix should include any character immediately preceding the numeric value and underscore, e.g., "t2_".
- to_prefix
the new prefix to replace the original prefix in the outcome variable, defaulting to "t0". the prefix should be in the same format as `from_prefix`, including the character immediately preceding the numeric value and underscore, e.g., "t0_".