EVOLUTION-MANAGER
Edit File: str_subset.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: Keep strings matching a pattern, or find positions.</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 str_subset {stringr}"><tr><td>str_subset {stringr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Keep strings matching a pattern, or find positions.</h2> <h3>Description</h3> <p><code>str_subset()</code> is a wrapper around <code>x[str_detect(x, pattern)]</code>, and is equivalent to <code>grep(pattern, x, value = TRUE)</code>. <code>str_which()</code> is a wrapper around <code>which(str_detect(x, pattern))</code>, and is equivalent to <code>grep(pattern, x)</code>. See <code><a href="str_detect.html">str_detect()</a></code> for an equivalent to <code>grepl(pattern, x)</code>. </p> <h3>Usage</h3> <pre> str_subset(string, pattern, negate = FALSE) str_which(string, pattern, negate = FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>string</code></td> <td> <p>Input vector. Either a character vector, or something coercible to one.</p> </td></tr> <tr valign="top"><td><code>pattern</code></td> <td> <p>Pattern to look for. </p> <p>The default interpretation is a regular expression, as described in <a href="../../stringi/html/stringi-search-regex.html">stringi::stringi-search-regex</a>. Control options with <code><a href="modifiers.html">regex()</a></code>. </p> <p>Match a fixed string (i.e. by comparing only bytes), using <code><a href="modifiers.html">fixed()</a></code>. This is fast, but approximate. Generally, for matching human text, you'll want <code><a href="modifiers.html">coll()</a></code> which respects character matching rules for the specified locale. </p> <p>Match character, word, line and sentence boundaries with <code><a href="modifiers.html">boundary()</a></code>. An empty pattern, "", is equivalent to <code>boundary("character")</code>.</p> </td></tr> <tr valign="top"><td><code>negate</code></td> <td> <p>If <code>TRUE</code>, return non-matching elements.</p> </td></tr> </table> <h3>Details</h3> <p>Vectorised over <code>string</code> and <code>pattern</code> </p> <h3>Value</h3> <p>A character vector. </p> <h3>See Also</h3> <p><code><a href="../../base/html/grep.html">grep()</a></code> with argument <code>value = TRUE</code>, <code><a href="../../stringi/html/stri_subset.html">stringi::stri_subset()</a></code> for the underlying implementation. </p> <h3>Examples</h3> <pre> fruit <- c("apple", "banana", "pear", "pinapple") str_subset(fruit, "a") str_which(fruit, "a") str_subset(fruit, "^a") str_subset(fruit, "a$") str_subset(fruit, "b") str_subset(fruit, "[aeiou]") # Returns elements that do NOT match str_subset(fruit, "^p", negate = TRUE) # Missings never match str_subset(c("a", NA, "b"), ".") str_which(c("a", NA, "b"), ".") </pre> <hr /><div style="text-align: center;">[Package <em>stringr</em> version 1.4.0 <a href="00Index.html">Index</a>]</div> </body></html>