getLabelVar {clinUtils} | R Documentation |
Get label for a variable of the dataset
Description
The label is extracted either (in this order):
if
label
is specified: from this label based on names, or directly from this label iflabel
andvar
are of length 1 (if available)if
labelVars
is specified: from the specified vector of labels, based on names (if available)if
data
is specified: from the 'label' attribute of the corresponding column indata
(if available)
If the label is not available, the input variable is returned.
Usage
getLabelVar(var, data = NULL, labelVars = NULL, label = NULL)
Arguments
var |
Character vector with variables of interest. |
data |
Data.frame with data. |
labelVars |
Named character vector with variable labels (names are the variable code),
usually extracted from |
label |
(Named) Character vector with user-specified label for |
Value
Named character vector with label, var
is no label is available
Author(s)
Laure Cougnaud
Examples
data(dataADaMCDISCP01)
labelVars <- attr(dataADaMCDISCP01, "labelVars")
# (upon reading the data with haven: attributes should directly available in each column)
getLabelVar(data = dataADaMCDISCP01, var = "AEREL")
# but if the data as data.frame is subsetted, label is lost
# so better to use 'labelVars':
getLabelVar(var = "AEREL", labelVars = labelVars)