Learn R Programming

memisc (version 0.99.31.8)

charTrans: Character Translation of Aspects of Objects

Description

This function uses the base package function chartr to translate characters in variable descriptions (a.k.a variable labels) and value labels of item, data.set, and importer objects.

It will be useful when the encoding of an important data set cannot be fully identified or if the encoding in the data file is incorrect or unknown.

Usage

charTrans(x, old = "", new = "", ...)
# S3 method for annotation
charTrans(x, old = "", new = "", ...)
# S3 method for data.set
charTrans(x, old = "", new = "", ...)
# S3 method for importer
charTrans(x, old = "", new = "", ...)
# S3 method for item
charTrans(x, old = "", new = "", ...)
# S3 method for value.labels
charTrans(x, old = "", new = "", ...)

Value

charTrans returns a copy of its first argument with character-translated character data or attributes.

Arguments

x

a character vector or an object of which character data or attributes character-translated.

old

a string with the characters to be translated.

new

a string with the translated characters.

...

further arguments, currently ignored.

See Also

Examples

Run this code
if (FALSE) {
# Locate an SPSS 'portable' file and get info on variables, their labels 
S2601.POR <- spss.portable.file("POR-Files/S2601.POR", encoded = "cp850")
# 'ß' appears to be correctly coded, but 'ä', 'ö', 'ü' are not, so we need to
# to some fine-tuning
S2601.POR <- charTrans(S2601.POR, old="{|}\r", new="äöü ")
# Now labels etc. are correctly encoded.
codebook(S2601.POR)
}

Run the code above in your browser using DataLab