Learn R Programming

DescTools (version 0.99.39)

RevCode: 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.

Value

the recoded vector

Details

The function recodes based on:

lbound + ubound - x

See Also

Recode

Examples

Run this code
# NOT RUN {
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))
# }

Run the code above in your browser using DataLab