| RevCode {DescTools} | R Documentation |
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.
RevCode(x, lbound = min(x, na.rm = TRUE), ubound = max(x, na.rm = TRUE))
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 |
ubound |
the high bound of the variable, default is the maximal value of |
The function recodes based on:
lbound + ubound - x
the recoded vector
Andri Signorell <andri@signorell.net>
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))