fct_match: Test for presence of levels in a factor

Description Usage Arguments Value Examples

View source: R/match.R

Description

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.

Usage

1

Arguments

f

A factor (or character vector).

lvls

A character vector specifying levels to look for.

Value

A logical vector

Examples

1
2
3
4
5
6
7
8
table(fct_match(gss_cat$marital, c("Married", "Divorced")))

# Compare to %in%, misspelled levels throw an error
table(gss_cat$marital %in% c("Maried", "Davorced"))
## Not run: 
table(fct_match(gss_cat$marital, c("Maried", "Davorced")))

## End(Not run)

sindribaldur/poorcats documentation built on Feb. 26, 2021, 12:27 a.m.