gcs {pedalfast.data} | R Documentation |
GCS Factor/Integer
Description
Functions for mapping integer values to GCS labeled factor and visa versa
Usage
gcs_as_integer(x, scale, ...)
## S3 method for class 'factor'
gcs_as_integer(x, scale, ...)
## S3 method for class 'character'
gcs_as_integer(x, scale, ...)
gcs_as_factor(x, scale, long_label = FALSE, highest_first = FALSE, ...)
## S3 method for class 'character'
gcs_as_factor(x, scale, long_label = FALSE, highest_first = FALSE, ...)
## S3 method for class 'numeric'
gcs_as_factor(x, scale, long_label = FALSE, highest_first = FALSE, ...)
gcs_ll
Arguments
x |
a integer, factor, or character vector. |
scale |
a character string to denote eye, motor, or verbal GCS scale. |
... |
not currently used. |
long_label |
logical to prepend the numeric value to the label of a factor. |
highest_first |
logical if the factor levels should be ordered with the highest GCS score as the reference level, else the lowest GCS score as the reference level. |
Format
An object of class list
of length 3.
Value
gcs_as_factor
returns a factor of equal length to x
.
gcs_as_integer
returns an integer vector of equal length to x
.
Examples
########################################
# 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)
[Package pedalfast.data version 1.0.1 Index]