Learn R Programming

codelist (version 0.1.0)

codes: Get the codes belonging to given labels

Description

Get the codes belonging to given labels

Usage

codes(x, ...)

# S3 method for default codes(x, codelist, locale = cl_locale(codelist), ...)

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

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

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.

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.

See Also

See as.label for an alternative in comparisons.

Examples

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

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

Run the code above in your browser using DataLab