make_dicho() converts a variable to a two-level factor by stripping the
first qualifier word from each level label and grouping the resulting stems.
For example, a 4-level Likert scale with labels
c("Strongly agree", "Agree", "Disagree", "Strongly disagree") collapses
to c("Agree", "Disagree") by removing the qualifier "Strongly".
When called inside mutate(), metadata is recorded in
@metadata@transformations[[col]].
Arguments
- x
Vector. Same types as
make_factor().- flip_levels
logical(1). IfTRUE, reverse the order of the two output levels.- .exclude
characterorNULL. Level name(s) to set toNAbefore collapsing. Intended for middle categories and "don't know"/"refused".- .label
character(1)orNULL. Variable label override. Falls back toattr(x, "label")then the column name.- .description
character(1)orNULL. Transformation description.
See also
Other transformation:
make_binary(),
make_factor(),
make_flip(),
make_rev()
Examples
library(dplyr)
x <- factor(
c("Always agree", "Sometimes agree", "Sometimes disagree", "Always disagree"),
levels = c("Always agree", "Sometimes agree", "Sometimes disagree",
"Always disagree")
)
make_dicho(x)
#> Always agree Sometimes agree Sometimes disagree Always disagree
#> Agree Agree Disagree Disagree
#> attr(,"label")
#> [1] x
#> attr(,"surveytidy_recode")
#> attr(,"surveytidy_recode")$fn
#> [1] make_dicho
#>
#> attr(,"surveytidy_recode")$var
#> [1] x
#>
#> attr(,"surveytidy_recode")$description
#> NULL
#>
#> Levels: Agree Disagree
