########################################
# Mapping from numeric values to factor:
nums <- c(0:7, 2.3)
# with short labels
data.frame(nums = nums,
eye = gcs_as_factor(nums, scale = "eye"),
motor = gcs_as_factor(nums, scale = "motor"),
verbal = gcs_as_factor(nums, scale = "verbal"))
# with long labels
data.frame(nums = nums,
eye = gcs_as_factor(nums, scale = "eye", long_label = TRUE),
motor = gcs_as_factor(nums, scale = "motor", long_label = TRUE),
verbal = gcs_as_factor(nums, scale = "verbal", long_label = TRUE))
###################################################
# Mapping from factors/characters to numeric values
# A quick way to access the labels and numeric values
pedalfast.data::gcs_ll
all_levels <- do.call(c, lapply(pedalfast.data::gcs_ll, names))
data.frame(lvls = all_levels,
eye = gcs_as_integer(all_levels, scale = "eye"),
motor = gcs_as_integer(all_levels, scale = "motor"),
verbal = gcs_as_integer(all_levels, scale = "verbal")
)
##################################################
# Order of the levels:
# The data values are the same, but the order of the levels differs.
gcs_as_factor(1:4, "eye", highest_first = FALSE)
gcs_as_factor(1:4, "eye", highest_first = TRUE)
Run the code above in your browser using DataLab