set_labels: Set variable labels

View source: R/lblCode.R

set_labelsR Documentation

Set variable labels

Description

Assign variable labels to a data.frame from a lookup table.

Usage

set_labels(data, names_labels)

Arguments

data

data frame to be labelled

names_labels

data frame with column 1 containing variable names from data and column 2 containing variable labels. Other columns will be ignored.

Details

Useful if variable labels have been imported from a data dictionary. The first column in names_labels must contain the variable name and the second column the variable label. The column names are not used.

If no label is provided then the existing label will not be changed. To remove a label set the label to NA.

See Also

set_var_labels() for setting individual variable labels, extract_labels() for creating a data frame of all variable labels, clear_labels() for removing variable labels

Examples

data("ctDNA")
# create data frame with labels
lbls <- data.frame(c1=c('cohort','size_change'),
c2=c('Cancer cohort','Change in tumour size'))
# set labels and return labelled data frame
set_labels(ctDNA,lbls)

reportRmd documentation built on April 4, 2025, 2:03 a.m.