| 1 |
\name{reversed} |
| 2 |
\alias{reversed} |
| 3 |
\alias{reversed,item.vector-method} |
| 4 |
\alias{reversed,factor-method} |
| 5 |
\title{Reverse the codes of a survey item or the levels of a factor} |
| 6 |
\description{ |
| 7 |
The function \code{reversed()} returns a copy of its argument with codes |
| 8 |
or levels in reverse order. |
| 9 |
} |
| 10 |
\usage{ |
| 11 |
reversed(x) |
| 12 |
\S4method{reversed}{item.vector}(x) |
| 13 |
\S4method{reversed}{factor}(x) |
| 14 |
} |
| 15 |
\arguments{ |
| 16 |
\item{x}{An object -- an "item" object or a "data.set" object} |
| 17 |
} |
| 18 |
\value{ |
| 19 |
If the argument of the function \code{reversed()} than either the |
| 20 |
unique valid values or the labelled valid values recoded into the |
| 21 |
reverse order. |
| 22 |
|
| 23 |
If th argument is a factor than the function returns the factor with |
| 24 |
levels in reverse order. |
| 25 |
} |
| 26 |
\examples{ |
| 27 |
ds <- data.set( |
| 28 |
x = as.item(sample(c(1:3,9),100,replace=TRUE), |
| 29 |
labels=c("One"=1, |
| 30 |
"Two"=2, |
| 31 |
"Three"=3, |
| 32 |
"Missing"=9))) |
| 33 |
df <- as.data.frame(ds) |
| 34 |
ds <- within(ds,{ |
| 35 |
xr <- reversed(x) |
| 36 |
}) |
| 37 |
codebook(ds) |
| 38 |
df <- within(df,{ |
| 39 |
xr <- reversed(x) |
| 40 |
}) |
| 41 |
codebook(df) |
| 42 |
} |