make_rev() reverses the direction of a numeric scale variable using the
formula min(x) + max(x) - x. This preserves the scale range: a 1-4 scale
reversed stays a 1-4 scale; a 2-5 scale reversed stays a 2-5 scale.
Value labels are remapped: each label's numeric value becomes min + max - old_value, so the label string stays tied to its original concept at its
new position.
When called inside mutate(), metadata is recorded in
@metadata@transformations[[col]].
Value
A numeric vector (same typeof() as x) with reversed values.
See also
Other transformation:
make_binary(),
make_dicho(),
make_factor(),
make_flip()
Examples
x <- c(1, 2, 3, 4)
make_rev(x)
#> [1] 4 3 2 1
#> attr(,"label")
#> [1] "x"
#> attr(,"surveytidy_recode")
#> attr(,"surveytidy_recode")$fn
#> [1] "make_rev"
#>
#> attr(,"surveytidy_recode")$var
#> [1] "x"
#>
#> attr(,"surveytidy_recode")$description
#> NULL
#>
