# NOT RUN {
## Example 1: Character to Character Mapping ##
# Set up vector
v1 <- c("A", "B", "C", "B")
# Define format
fmt1 <- value(condition(x == "A", "Label A"),
condition(x == "B", "Label B"),
condition(TRUE, "Other"))
# Apply format to vector
fapply(v1, fmt1)
## Example 2: Character to Integer Mapping ##
fmt2 <- value(condition(x == "A", 1),
condition(x == "B", 2),
condition(TRUE, 3))
# Apply format to vector
fapply(v1, fmt2)
## Example 3: Categorization of Continuous Variable ##
# Set up vector
v2 <- c(1, 6, 11, 7)
# Define format
fmt3 <- value(condition(x < 5, "Low"),
condition(x >= 5 & x < 10, "High"),
condition(TRUE, "Out of range"))
# Apply format to vector
fapply(v2, fmt3)
# }
Run the code above in your browser using DataLab