Skip to contents

Occasionally dataframe columns have not been named logically and consistent in the software where the data originates. This function renames variable names based on patterns in the variable labels, after ignoring some stop words.

Usage

rename_by_labels(
  data,
  label_sep = " - ",
  sort_var = c("pos", "variable", "label"),
  new_var_sep = "_",
  stop_words = NULL
)

Arguments

data

Dataset.

label_sep

The separator between group part and unique part of label.

sort_var

When numbering variables within a group, what to sort by? pos is original position in dataset, variable is variable name (alphabetical), and label is label (alphabetical)

new_var_sep

When creating new variables, how to glue together variable group name prefix and numbering?

stop_words

Words to ignore in label when abbreviating label to name.

Value

Data with renamed variable names.