Skip to contents

This function adds "label" attributes to all columns in a dataset

Usage

apply_labels(data, labels_df, type)

Arguments

data

The dataset to which labels will be applied.

labels_df

A data frame with three columns: Variable, Label, and Dataset, for the dataset you are applying it .

type

The type variable in labels_df for which the labels are to be applied.

Value

The same dataset with label attributes applied to all columns. If a column is not present in the labels list, it will be assigned the name of the col.

Examples

if (FALSE) { # \dontrun{
  # Example usage:
  data <- data.frame(USUBJID = c(1, 2, 3), AVAL = c(4, 5, 6))
  labels <- data.frame(
  Variable = c("USUBJID", "AVAL"),
  Label = c("Unique Subject Identifier", "Analysis Value")
  )
  data <- apply_labels(data, labels)
  print(attr(data$A, "label"))
} # }