Learn R Programming

memisc (version 0.99.31.8)

trim_labels: Trim Codes from the Labels of an Item

Description

Occasionally, labels of codes in a survey data sets (e.g. from the 2016 American National Election Study) include a character representation of the codes being labelled. While there may be technical reasons for this, it is often inconvenient (e.g. if one wants to reorder the labelled codes). The function trim_labels trims the code representations (if they are present.)

Usage

trim_labels(x,...)
# S4 method for item.vector
trim_labels(x,...)
# S4 method for data.set
trim_labels(x,...)

Arguments

x

An object -- an "item" object or a "data.set" object

...

Further arguments, currently ignored

Details

The "data.set" method applies the "item.vector" method to all the labelled items in the data set.

The "item.vector" returns a copy of its argument with modified labels, where a label such as "1. First alternative" is changed into "First alternative".

Examples

Run this code
x <- as.item(sample(1:3,10,replace=TRUE),
             labels=c("1. One"=1,
                      "2. Two"=2,
                      "2. Three"=3))
y <- as.item(sample(1:2,10,replace=TRUE),
             labels=c("1. First category"=1,
                      "2. Second category"=2))
ds <- data.set(x,y)
x <- trim_labels(x)
codebook(x)
ds <- trim_labels(ds)
codebook(ds)

Run the code above in your browser using DataLab