Learn R Programming

memisc (version 0.99.31.7)

reversed: Reverse the codes of a survey item or the levels of a factor

Description

The function reversed() returns a copy of its argument with codes or levels in reverse order.

Usage

reversed(x)
# S4 method for item.vector
reversed(x)
# S4 method for factor
reversed(x)

Value

If the argument of the function reversed() than either the unique valid values or the labelled valid values recoded into the reverse order.

If th argument is a factor than the function returns the factor with levels in reverse order.

Arguments

x

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

Examples

Run this code
ds <- data.set(
    x = as.item(sample(c(1:3,9),100,replace=TRUE),
                labels=c("One"=1,
                         "Two"=2,
                         "Three"=3,
                         "Missing"=9)))
df <- as.data.frame(ds)
ds <- within(ds,{
    xr <- reversed(x)
})
codebook(ds)
df <- within(df,{
    xr <- reversed(x)
})
codebook(df)

Run the code above in your browser using DataLab