RevCode {DescTools} | R Documentation |
Reverse Codes
Description
In psychology variables often need to be recoded into reverse order in cases that items are negatively worded. So it can be ensured that a high value indicate the same type of response on every item. 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, ...)
Arguments
x |
a numerical or logical vector, or a factor. |
... |
the dots are sent to |
Details
The function recodes based on:
min(x, na.rm=TRUE) + max(x, na.rm=TRUE) - x
Value
the recoded vector
Author(s)
Andri Signorell <andri@signorell.net>
See Also
Examples
x <- 1:5
data.frame(x, rev_num=RevCode(x), rev_fac=RevCode(factor(x)))
s <- c(3,4,2,7,4,9,NA,10)
RevCode(factor(s, levels=1:10))
i <- c(1,0,0,0,1,1)
cbind(i, RevCode(i))
k <- as.logical(c(1,0,0,0,1,1))
cbind(k, RevCode(k))
x <- factor(sample(letters[1:5], 10, replace = TRUE))
RevCode(x)
# we want to set the level 5 to NA before reversing
RevCode(factor(NAIf(x, "e")))
[Package DescTools version 0.99.55 Index]