make_flip() reverses the label string associations of a numeric variable
without changing its values. This is used to flip the polarity of a survey
item for composite scoring - for example, converting "I like the color blue"
to "I dislike the color blue" without changing the underlying numeric codes.
Unlike make_rev(), which changes numeric values and keeps label strings in
place, make_flip() keeps values unchanged and reverses which label strings
are attached to which values.
A new variable label is required because flipping always changes the semantic meaning of the variable.
When called inside mutate(), metadata is recorded in
@metadata@transformations[[col]].
Value
A numeric vector (same typeof() as x). Values are unchanged.
See also
Other transformation:
make_binary(),
make_dicho(),
make_factor(),
make_rev()
Examples
x <- c(1, 2, 3, 4)
attr(x, "labels") <- c("Strongly agree" = 1, "Agree" = 2,
"Disagree" = 3, "Strongly disagree" = 4)
make_flip(x, "I dislike the color blue")
#> [1] 1 2 3 4
#> attr(,"labels")
#> Strongly disagree Disagree Agree Strongly agree
#> 1 2 3 4
#> attr(,"label")
#> [1] "I dislike the color blue"
#> attr(,"surveytidy_recode")
#> attr(,"surveytidy_recode")$fn
#> [1] "make_flip"
#>
#> attr(,"surveytidy_recode")$var
#> [1] "x"
#>
#> attr(,"surveytidy_recode")$description
#> NULL
#>
