| 1 |
\name{trim_labels} |
| 2 |
\alias{trim_labels} |
| 3 |
\alias{trim_labels,item.vector-method} |
| 4 |
\alias{trim_labels,data.set-method} |
| 5 |
\title{Trim Codes from the Labels of an Item} |
| 6 |
\description{ |
| 7 |
Occasionally, labels of codes in a survey data sets (e.g. from the |
| 8 |
2016 American National Election Study) include a |
| 9 |
character representation of the codes being labelled. While there may |
| 10 |
be technical reasons for this, it is often inconvenient (e.g. if one |
| 11 |
wants to reorder the labelled codes). The function \code{trim_labels} |
| 12 |
trims the code representations (if they are present.) |
| 13 |
} |
| 14 |
\usage{ |
| 15 |
trim_labels(x,\dots) |
| 16 |
\S4method{trim_labels}{item.vector}(x,\dots) |
| 17 |
\S4method{trim_labels}{data.set}(x,\dots) |
| 18 |
} |
| 19 |
\arguments{ |
| 20 |
\item{x}{An object -- an "item" object or a "data.set" object} |
| 21 |
\item{\dots}{Further arguments, currently ignored} |
| 22 |
} |
| 23 |
\details{ |
| 24 |
The "data.set" method applies the "item.vector" method to all the |
| 25 |
labelled items in the data set. |
| 26 |
|
| 27 |
The "item.vector" returns a copy of its argument with modified labels, |
| 28 |
where a label such as "1. First alternative" is changed into "First alternative". |
| 29 |
} |
| 30 |
\examples{ |
| 31 |
x <- as.item(sample(1:3,10,replace=TRUE), |
| 32 |
labels=c("1. One"=1, |
| 33 |
"2. Two"=2, |
| 34 |
"2. Three"=3)) |
| 35 |
y <- as.item(sample(1:2,10,replace=TRUE), |
| 36 |
labels=c("1. First category"=1, |
| 37 |
"2. Second category"=2)) |
| 38 |
ds <- data.set(x,y) |
| 39 |
x <- trim_labels(x) |
| 40 |
codebook(x) |
| 41 |
ds <- trim_labels(ds) |
| 42 |
codebook(ds) |
| 43 |
} |