EVOLUTION-MANAGER
Edit File: vec_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: Find matching observations across vectors</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 vec_match {vctrs}"><tr><td>vec_match {vctrs}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Find matching observations across vectors</h2> <h3>Description</h3> <p><code>vec_in()</code> returns a logical vector based on whether <code>needle</code> is found in haystack. <code>vec_match()</code> returns an integer vector giving location of <code>needle</code> in <code>haystack</code>, or <code>NA</code> if it's not found. </p> <h3>Usage</h3> <pre> vec_match( needles, haystack, ..., na_equal = TRUE, needles_arg = "", haystack_arg = "" ) vec_in( needles, haystack, ..., na_equal = TRUE, needles_arg = "", haystack_arg = "" ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>needles, haystack</code></td> <td> <p>Vector of <code>needles</code> to search for in vector haystack. <code>haystack</code> should usually be unique; if not <code>vec_match()</code> will only return the location of the first match. </p> <p><code>needles</code> and <code>haystack</code> are coerced to the same type prior to comparison.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>These dots are for future extensions and must be empty.</p> </td></tr> <tr valign="top"><td><code>na_equal</code></td> <td> <p>If <code>TRUE</code>, missing values in <code>needles</code> can be matched to missing values in <code>haystack</code>. If <code>FALSE</code>, they propagate, missing values in <code>needles</code> are represented as <code>NA</code> in the return value.</p> </td></tr> <tr valign="top"><td><code>needles_arg, haystack_arg</code></td> <td> <p>Argument tags for <code>needles</code> and <code>haystack</code> used in error messages.</p> </td></tr> </table> <h3>Details</h3> <p><code>vec_in()</code> is equivalent to <a href="../../base/html/match.html">%in%</a>; <code>vec_match()</code> is equivalent to <code>match()</code>. </p> <h3>Value</h3> <p>A vector the same length as <code>needles</code>. <code>vec_in()</code> returns a logical vector; <code>vec_match()</code> returns an integer vector. </p> <h3>Missing values</h3> <p>In most cases places in R, missing values are not considered to be equal, i.e. <code>NA == NA</code> is not <code>TRUE</code>. The exception is in matching functions like <code><a href="../../base/html/match.html">match()</a></code> and <code><a href="../../base/html/merge.html">merge()</a></code>, where an <code>NA</code> will match another <code>NA</code>. By <code>vec_match()</code> and <code>vec_in()</code> will match <code>NA</code>s; but you can control this behaviour with the <code>na_equal</code> argument. </p> <h3>Dependencies</h3> <ul> <li> <p><code><a href="vec_cast.html">vec_cast_common()</a></code> with fallback </p> </li> <li> <p><code><a href="vec_proxy_equal.html">vec_proxy_equal()</a></code> </p> </li></ul> <h3>Examples</h3> <pre> hadley <- strsplit("hadley", "")[[1]] vec_match(hadley, letters) vowels <- c("a", "e", "i", "o", "u") vec_match(hadley, vowels) vec_in(hadley, vowels) # Only the first index of duplicates is returned vec_match(c("a", "b"), c("a", "b", "a", "b")) </pre> <hr /><div style="text-align: center;">[Package <em>vctrs</em> version 0.5.0 <a href="00Index.html">Index</a>]</div> </body></html>