
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.
label(x, value=NULL, data=mydata)
The variable for which to obtain the corresponding variable label.
If assigned, then the specified data frame is updated with this assigned label.
Data frame that contains the variable of interest. The output of the function is assigned to this data frame.
The specified value of value
is returned.
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 mydata
. 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.
Read
.
# NOT RUN {
# read the internal lessR data frame that contains variable labels
mydata <- Read("Employee", format="lessR")
# variable label as the title of a graph from a standard R function
# the data are not attached, so for standard R functions, must
# identify the relevant data frame, such as with function: with
with(mydata, barplot(table(Dept), main=label(Dept)))
with(mydata, hist(Salary, main=label(Salary)))
# assign a new label for the variable Years in mydata
mydata <- label(Years, "Years Worked")
# verify
label(Years)
# or view all variable labels in mydata
details.brief()
mydata <- Read("Employee", format="lessR")
# specify a label of variable in a data frame other than mydata
myd <- Subset(Gender=="M")
myd <- label(Gender, "Only is Male", data=myd)
details.brief(myd)
# }
Run the code above in your browser using DataLab