labels.code {codelist} | R Documentation |
Convert vector with codes to factor using a code list
Description
Convert vector with codes to factor using a code list
Usage
## S3 method for class 'code'
labels(
object,
missing = TRUE,
droplevels = FALSE,
codelist = attr(object, "codelist"),
locale = cl_locale(codelist),
...
)
to_labels(
x,
codelist = attr(x, "codelist"),
missing = TRUE,
droplevels = FALSE,
locale = cl_locale(codelist)
)
Arguments
object |
vector with codes. Should be of the same type as the codes in the codelist. |
missing |
convert codes that are missing value to missing values. |
droplevels |
remove labels that do not occur in |
codelist |
a |
locale |
use the codes from the given locale. Should be character vector of length 1. |
... |
ignored |
x |
vector with codes. Should be of the same type as the codes in the codelist. |
Details
to_labels
calls labels.code
directly and is meant as a
substitute for labels.code
for objects that are not of type 'code'.
Value
A factor vector with the same length as x
.
Examples
data(objectsales)
data(objectcodes)
objectsales$product <- code(objectsales$product, objectcodes)
labels(objectsales$product) |>
table(useNA = "ifany")
labels(objectsales$product, missing = FALSE) |>
table(useNA = "ifany")
labels(objectsales$product, droplevels = TRUE) |>
table(useNA = "ifany")
to_labels(c("A", "B"), codelist = objectcodes)
# is the same as
labels.code(c("A", "B"), codelist = objectcodes)
[Package codelist version 0.1.0 Index]