EVOLUTION-MANAGER
Edit File: fct_match.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Test for presence of levels in a factor</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for fct_match {forcats}"><tr><td>fct_match {forcats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Test for presence of levels in a factor</h2> <h3>Description</h3> <p>Do any of <code>lvls</code> occur in <code>f</code>? Compared to <a href="../../base/html/match.html">%in%</a>, this function validates <code>lvls</code> to ensure that they're actually present in <code>f</code>. In other words, <code>x %in% "not present"</code> will return <code>FALSE</code>, but <code>fct_match(x, "not present")</code> will throw an error. </p> <h3>Usage</h3> <pre> fct_match(f, lvls) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>f</code></td> <td> <p>A factor (or character vector).</p> </td></tr> <tr valign="top"><td><code>lvls</code></td> <td> <p>A character vector specifying levels to look for.</p> </td></tr> </table> <h3>Value</h3> <p>A logical vector </p> <h3>Examples</h3> <pre> 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) </pre> <hr /><div style="text-align: center;">[Package <em>forcats</em> version 0.5.0 <a href="00Index.html">Index</a>]</div> </body></html>