Unlike standard R, lessR
provides for variable labels, here stored in the data frame mylabels
. To read the labels from an external file, specify a file reference as the first argument of the function call. Or create a character string of variable names and labels and specify the character string as the first argument to the function call. To assign an individual variable label with this function specify the variable name as the first argument followed by the label in quotes. Not all variables need have a label, and the variables with their corresponding labels can be listed or assigned in any order. If the mylabels
data frame is created or modified, the output of the function must be assigned to mylabels
, as shown in the following examples.
When all or some of the labels are read, either from the console or an external csv
or Excel
file, each line of the file contains the variable name and then the associated variable label. The file types of .csv
and .xlsx
in the file reference listed in the first position of the function call are what trigger the interpretation of the argument as a file reference.
For a file that contains only labels, each row of the file, including the first row, consists of the variable name, a comma if a csv
file, and then the label. For the csv
form of the file, this is the standard csv
format such as obtained with the csv
option from a standard worksheet application such as Microsoft Excel or LibreOffice Calc. Not all variables in the data frame that contains the data, usually mydata
, need have a label, and the variables with their corresponding labels can be listed in any order. An example of this file follows for four variables, I1 through I4, and their associated labels.
I2,This instructor presents material in a clear and organized manner.
I4,Overall, this instructor was highly effective in this class.
I1,This instructor has command of the subject.
I3,This instructor relates course materials to real world situations.
If there is a comma in the variable label, then the label needs to be enclosed in quotes.
The lessR
functions that provide analysis, such as Histogram
for a histogram, automatically include the variable labels in their output, such as the title of a graph. Standard R functions can also use these variable labels by invoking the lessR
function label
, such as setting main=label(I4)
to put the variable label for a variable named I4 in the title of a graph.
Variable units may also be added to the third column of a variable label file. These are used for generating a better natural language text in the generation of R~Markdown files with the Rmd
option on supporting functions such as Regression
. For currency (USD), indicate with unit: dollar.
a