1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/match.R
3\name{fct_match}
4\alias{fct_match}
5\title{Test for presence of levels in a factor}
6\usage{
7fct_match(f, lvls)
8}
9\arguments{
10\item{f}{A factor (or character vector).}
11
12\item{lvls}{A character vector specifying levels to look for.}
13}
14\value{
15A logical vector
16}
17\description{
18Do any of \code{lvls} occur in \code{f}? Compared to \link{\%in\%}, this function validates
19\code{lvls} to ensure that they're actually present in \code{f}. In other words,
20\code{x \%in\% "not present"} will return \code{FALSE}, but \code{fct_match(x, "not present")}
21will throw an error.
22}
23\examples{
24table(fct_match(gss_cat$marital, c("Married", "Divorced")))
25
26# Compare to \%in\%, misspelled levels throw an error
27table(gss_cat$marital \%in\% c("Maried", "Davorced"))
28\dontrun{
29table(fct_match(gss_cat$marital, c("Maried", "Davorced")))
30}
31
32}
33