This function adds "label" attributes to all columns in a dataset
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. If label already exists in the original data, it will be preserved.
Examples
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"),
Dataset = c("ADPC", "ADPC")
)
data <- apply_labels(data, labels, "ADPC")
print(attr(data$USUBJID, "label")) # "Unique Subject Identifier"
#> [1] "Unique Subject Identifier"
print(attr(data$AVAL, "label")) # "Analysis Value"
#> [1] "Analysis Value"