reverses {quest} | R Documentation |
Reverse Code Numeric Data
Description
reverses
reverse codes numeric data based on minimum and maximum
values. For example, say numerical values of response options can range from
1 to 4. The function will change 1 to 4, 2 to 3, 3 to 2, and 4 to 1. If there
are an odd number of response options, the middle in the sequence will be
unchanged.
Usage
reverses(data, vrb.nm, mini, maxi, suffix = "_r")
Arguments
data |
data.frame of data. |
vrb.nm |
character vector of colnames from |
mini |
numeric vector of length 1 specifying the minimum numeric value. |
maxi |
numeric vector of length 1 specifying the maximum numeric value. |
suffix |
character vector of length 1 specifying the string to add to the end of the colnames in the return object. |
Details
reverses
is simply a vectorized version of reverse
to more
easily reverse code multiple columns of a data.frame at the same time.
Value
data.frame of reverse coded variables with colnames specified by
paste0(vrb.nm, suffix)
.
See Also
Examples
tmp <- !(is.element(el = names(psych::bfi) , set = c("gender","education","age")))
vrb_nm <- names(psych::bfi)[tmp]
reverses(data = psych::bfi, vrb.nm = vrb_nm, mini = 1, maxi = 6)