codes: Get the codes belonging to given labels

View source: R/codes.R

codesR Documentation

Get the codes belonging to given labels

Description

Get the codes belonging to given labels

Usage

codes(x, ...)

## Default S3 method:
codes(x, codelist, locale = cl_locale(codelist), ...)

## S3 method for class 'code'
codes(x, ...)

to_codes(x, codelist, locale = cl_locale(codelist))

Arguments

x

character vector with labels.

...

used to pass arguments to other methods.

codelist

a codelist object or a data.frame that is a valid code list or and object that has a 'codelist' attribute containing a codelist.

locale

use the codes from the given locale. Should be a character vector of length 1.

Details

to_codes has the same functionality as a call to codes.default.

Value

Returns a vector of codes. Will give an error when one of the labels cannot be found in the codelist for the given locale. When x is an object of type 'code' the codes themselves are returned stripped from the 'code' class and with the 'codelist' attribute removed.

See Also

See as.label for an alternative in comparisons.

Examples

data(objectcodes)
data(objectsales)
objectsales$product <- code(objectsales$product, objectcodes)

codes(c("Hammer", "Electric Drill"), objectcodes)
codes(c("Hammer", "Electric Drill"), cl(objectsales$product))


codelist documentation built on April 12, 2025, 2:25 a.m.