A value label is a string of text associated with a unique value of a categorical varaible. For example, the value of 2 in variables containing age data often represents people aged 18 to 24. There are four ways of setting value labels in Displayr:
Please note these steps require a Displayr license.
Setting them in the data file
Generally, data files imported into Displayr should have the value labels contained within them. See Find the Best Possible Data File.
Using the user interface
Value labels are added in the user interface by:
- Selecting the variable or variable set of interest in the data sets tree.
- Pressing Labels in the object inspector
- Typing in the labels and pressing OK.
Note that you will only see the labels on tables if the variable set's Structure has been set to Nominal, Ordinal, Nominal - Multi, Ordinal - Mult, Experiment, or Binary - Compact.
Using the factor function
This example continues on from Challenges With 'if' When Writing R Code.
Consider where we are creating two groups of people, younger and older people, using:
ifelse(age < Average(age), 1, 2)
We can create the value labels using:
factor(ifelse(age < Average(age), 1, 2), levels = 1:2, labels = c("Younger","Older"))
A slightly nicer way of writing this is to break it up into two stages:
x = ifelse(age < Average(age), 1, 2)
factor(x, levels = 1:2, labels = c("Younger","Older"))
This approach also allows you to create labels for variables that have no data associated. For example, let's say we suspected that in the future we may have people with no age data in the data and we wanted to give them a category, we could use the following code:
x = ifelse(age < Average(age), 1, 2)
x[is.na(x)] = 3
factor(x, levels = 1:3, labels = c("Younger", "Older", "UNKNOWN"))
QScript
Displayr has a JavaScript-based scripting language that can be used for automating things called QScript. It can be used to set value labels as well. See How to Create a Custom QScript.
See also
For a more general overview of using R in Displayr, see the Displayr Help section on R.