Learn R Programming

DDIwR (version 0.24)

recodeCharcat: Recode character categorical variables

Description

Recodes a character categorical variables to a numerical categorical variable.

Usage

recodeCharcat(x, ...)

Value

A numeric categorical variable of the same class as the input.

Arguments

x

A character categorical variable

...

Other internal arguments

Author

Adrian Dusa

Details

For this function, a categorical variable is something else than a base factor. It should be an object of class "declared" with a specific attribute called "labels" that stores the value labels.

Variable labels, display widths, custom SPSS attributes and Stata characteristics are retained. String formats and storage widths are removed when the values become numeric; subsequent exports derive numeric formats. The spss_metadata, stata_metadata and sas_metadata lists are also retained, except for their string storage fields (format, width, SAS informat and Stata type).

Examples

Run this code
x <- declared(
    c(letters[1:5], -91),
    labels = c(Good = "a", Bad = "e", NR = -91),
    na_values = -91
)

recodeCharcat(x)

Run the code above in your browser using DataLab