EVOLUTION-MANAGER
Edit File: stri_sub_all.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: Extract or Replace Multiple Substrings</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 stri_sub_all {stringi}"><tr><td>stri_sub_all {stringi}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Extract or Replace Multiple Substrings</h2> <h3>Description</h3> <p><code>stri_sub_all</code> extracts multiple substrings from each string. Its replacement version substitutes (in-place) multiple substrings with the corresponding replacement strings. <code>stri_sub_replace_all</code> (alias <code>stri_sub_all_replace</code>) is <span class="pkg">magrittr</span>'s pipe-operator-friendly variant, returning a copy of the input vector. </p> <p>For extracting/replacing single substrings from/within each string, see <code><a href="stri_sub.html">stri_sub</a></code>. </p> <h3>Usage</h3> <pre> stri_sub_all(str, from = list(1L), to = list(-1L), length) stri_sub_all(str, from=list(1L), to=list(-1L), length, omit_na=FALSE) <- value stri_sub_replace_all(..., replacement, value = replacement) stri_sub_all_replace(..., replacement, value = replacement) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>str</code></td> <td> <p>a character vector</p> </td></tr> <tr valign="top"><td><code>from</code></td> <td> <p>a list of integer vectors giving the start indexes or a list of two-column matrices, each of type <code>cbind(from, to)</code></p> </td></tr> <tr valign="top"><td><code>to</code></td> <td> <p>a list of integer vectors giving the end indexes</p> </td></tr> <tr valign="top"><td><code>length</code></td> <td> <p>a list of integer vectors giving the substring lengths</p> </td></tr> <tr valign="top"><td><code>omit_na</code></td> <td> <p>a single logical value; indicates whether missing values in any of the indexes or in <code>value</code> leave the part of the corresponding input string unchanged [replacement function only]</p> </td></tr> <tr valign="top"><td><code>value</code></td> <td> <p>a list of character vectors defining the replacement strings [replacement function only]</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>arguments to be passed to <code>stri_sub_all<-</code></p> </td></tr> <tr valign="top"><td><code>replacement</code></td> <td> <p>alias of <code>value</code> [wherever applicable]</p> </td></tr> </table> <h3>Details</h3> <p>Vectorized over <code>str</code>, [<code>value</code>], <code>from</code> and (<code>to</code> or <code>length</code>). Just like in <code><a href="stri_sub.html">stri_sub</a></code>, parameters <code>to</code> and <code>length</code> are mutually exclusive. </p> <p>In one of the simplest scenarios, <code>stri_sub_all(str, from, to)</code>, the i-th element of the resulting list is generated by calling, e.g., <code>stri_sub(str[i], from[[i]], to[[i]])</code>. As usual, if one of the inputs is of length smaller than the others, recycling rule is applied. </p> <p>If any of <code>from</code>, <code>to</code>, <code>length</code>, or <code>value</code> is not a list, it is wrapped into a list. </p> <p><code>from</code> can be a list of two-column matrices. In such a case, the two columns play a role of <code>from</code> and <code>to</code>, respectively. Such types of index matrices are generated by <code><a href="stri_locate.html">stri_locate_all</a></code>. If extraction or replacement based on <code><a href="stri_locate.html">stri_locate_first</a></code> or <code><a href="stri_locate.html">stri_locate_last</a></code> is needed, see <code><a href="stri_sub.html">stri_sub</a></code>. </p> <p>In the replacement function, the index ranges must be sorted with respect to <code>from</code> are must be mutually disjoint. </p> <h3>Value</h3> <p><code>stri_sub_all</code> returns a list of character vectors. Its replacement versions return a character vector. </p> <h3>See Also</h3> <p>Other indexing: <code><a href="stri_locate_boundaries.html">stri_locate_all_boundaries</a>()</code>, <code><a href="stri_locate.html">stri_locate_all</a>()</code>, <code><a href="stri_sub.html">stri_sub</a>()</code> </p> <h3>Examples</h3> <pre> x <- c("12 3456 789", "abc", "", NA, "667") stri_sub_all(x, stri_locate_all_regex(x, "[0-9]+")) # see stri_extract_all stri_sub_all(x, stri_locate_all_regex(x, "[0-9]+", omit_no_match=TRUE)) stri_sub_all(x, stri_locate_all_regex(x, "[0-9]+", omit_no_match=TRUE)) <- "***" print(x) stri_sub_replace_all("a b c", c(1, 3, 5), c(1, 3, 5), replacement=c("A", "B", "C")) </pre> <hr /><div style="text-align: center;">[Package <em>stringi</em> version 1.4.6 <a href="00Index.html">Index</a>]</div> </body></html>