update_variable_labels: Update Variable Labels

View source: R/update.R

update_variable_labelsR Documentation

Update Variable Labels

Description

This function is used to update the labels of variables in a given dataset. The labels are updated according to a specified set of new labels. If 'reverse' is set to TRUE, the order of variables and their corresponding labels are reversed before the update.

Usage

update_variable_labels(
  draws,
  reverse = FALSE,
  variables = epict::epict_priors(include_descriptive = TRUE)
)

Arguments

draws

A dataset (data.frame or data.table) containing the variables to be relabelled.

reverse

A logical value indicating whether to reverse the order of variables and their corresponding labels before updating (Default is FALSE).

variables

A data.frame providing the mapping from old variable names to new names. By default, it uses epict::epict_priors(include_descriptive = TRUE). The data.frame should contain 'variable' and 'name' columns where 'variable' is the old variable name and 'name' is the new variable name.

Value

A data.table with updated variable labels according to the input mapping. The returned data.table contains only the rows where variables were found and updated.

Examples

data <- data.frame(variable = c("v1", "v2", "v3"), value = c(1, 2, 3))
variables_mapping <- data.frame(
 variable= c("v1", "v2", "v3"),
 name = c("Variable 1", "Variable 2", "Variable 3")
)

updated_data <- update_variable_labels(data, FALSE, variables_mapping)
updated_data

seabbs/epict documentation built on July 3, 2023, 6:42 a.m.