Do any of lvls
occur in f
? Compared to %in%, this function validates
lvls
to ensure that they're actually present in f
. In other words,
x %in% "not present"
will return FALSE
, but fct_match(x, "not present")
will throw an error.
fct_match(f, lvls)
A logical vector
table(fct_match(gss_cat$marital, c("Married", "Divorced")))
#>
#> FALSE TRUE
#> 7983 13500
# Compare to %in%, misspelled levels throw an error
table(gss_cat$marital %in% c("Maried", "Davorced"))
#>
#> FALSE
#> 21483
if (FALSE) { # \dontrun{
table(fct_match(gss_cat$marital, c("Maried", "Davorced")))
} # }