R: Reverse Codes

RevCode {DescTools} | R Documentation

## Reverse Codes

### Description

In psychology variables often need to be recoded into the other direction (reverse coding). Let's say we have a Likert scale from 1 to 5 and we want to recode the variable so that a 5 becomes a 1, 4 a 2 and so on.

### Usage

    RevCode(x, lbound = min(x, na.rm = TRUE), ubound = max(x, na.rm = TRUE))

### Arguments

`x` | a numerical vector, will be converted to numeric if it's not.
`lbound` | the low bound of the variable, default is the minmal value of `x`.
`ubound` | the high bound of the variable, default is the maximal value of `x`.

### Details

The function recodes based on:

lbound + ubound - x

### Value

the recoded vector

### Author(s)

Andri Signorell <andri@signorell.net>

### See Also

`Recode`

### Examples

    s <- c(3,4,2,7,4,9,NA,10)
    RevCode(s, lbound=1, ubound=10)

    i <- c(1,0,0,0,1,1)
    cbind(i, RevCode(i))

[Package DescTools version 0.99.38 Index]