getLabelVar {clinUtils}R Documentation

Get label for a variable of the dataset

Description

The label is extracted either (in this order):

  1. if label is specified: from this label based on names, or directly from this label if label and var are of length 1 (if available)

  2. if labelVars is specified: from the specified vector of labels, based on names (if available)

  3. if data is specified: from the 'label' attribute of the corresponding column in data (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 data.

label

(Named) Character vector with user-specified label for var. Label is extracted based on names if variable is available. If var is of length 1, label can also be specified as an unnamed character.

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)

[Package clinUtils version 0.1.4 Index]