label {lessR} | R Documentation |
Assign Variable Labels [Superseded by VariableLabels]
Description
Deprecated, replaced by VariableLabels
. Display a variable label for output, either text output at the console or graphics, such as a title on a graph. To return a variable label generally applies to standard R functions such that the functions can access lessR
variable labels. Or, the variable name and label can be listed on the standard output. To assign a variable label, invoke the value
option and assign the output to a specified data frame.
Usage
label(x, value=NULL, data=d)
Arguments
x |
The variable for which to obtain the corresponding variable label. |
value |
If assigned, then the specified data frame is updated with this assigned label. |
data |
Data frame that contains the variable of interest. The output of the function is assigned to this data frame. |
Details
Standard R does not provide for variable labels, but lessR
does. Read the labels with the lessR
Read
function, as explained in the corresponding documentation. Individual variable labels can also be assigned with this function. Not all variables need have a label, and the variables with their corresponding labels can be listed or assigned in any order.
The function provides two different modes. The first mode is to return the variable name and label for an existing variable label. One such use is to provide the function as an argument to an existing R function call to access a lessR
variable label. For example, use the function as the argument for main
in graphics output, where main
is the title of the graph. This mode is triggered by not invoking the value
option.
The second mode is to assign a variable label to an existing variable. Invoke this mode by specifying a variable label with the value
option. The function accesses the entire specified data frame, and then modifies the specified variable label. As such, assign the output of the function to the data frame of interest, such as the default d
. One use of this function is to add a variable label to a data frame that contains a new variable created by a transformation of the existing variables.
Value
The specified value of value
is returned.
Author(s)
David W. Gerbing (Portland State University; gerbing@pdx.edu)
See Also
Read
.
Examples
# read the data and variable labels
#d <- rd("http://lessRstats.com/data/employee.xlsx")
#l <- vl("http://lessRstats.com/data/employee_lbl.xlsx")
# variable label as the title of a graph for non-lessR functions
# base R
#hist(d$Salary, xlab=label(Salary))
# ggplot2
#ggplot(d, aes(Salary)) + geom_histogram(binwidth=10000) + labs(x=label(Salary))
# assign a new label for the variable Years in d
#d <- label(Years, "Years Worked")
# verify
#label(Years)
# or view all variable labels in d
#db()
#d <- Read("Employee")
# specify a label of variable in a data frame other than d
#myd <- Subset(Gender=="M")
#myd <- label(Gender, "Only is Male", data=myd)
#db(myd)