Skip to contents

This function reverse-codes numeric variables. For example, a 1-7 Likert scale becomes a 7-1 Likert scale (1=7, 2=6, etc.). This is achieved by taking the maximum value of the variable, adding the minimum (acting as an offset), and subtracting each value.

Usage

reverse_code(df, vars, scale_min = NULL, scale_max = NULL)

Arguments

df

data.frame

vars

(character) vector of variable names

scale_min

(numeric, optional) minimum value on the scale (default is to use observed minimum value)

scale_max

(numeric, optional) maximum value on the scale (default is to use observed maximum value)

Value

df with vars reverse-coded

Examples

df <- df |> reverse_code("x1")
#> [1] "Reverse-coded these variables:"
#> [1] "x1"