Learn R Programming

tidyplus (version 0.2.0)

str_replace_vec: String replace multiple strings

Description

String replace multiple strings in a vector.

Usage

str_replace_vec(string, replace)

Value

A character vector the same length as string/pattern/replacement.

Arguments

string

Input vector. Either a character vector, or something coercible to one.

replace

A character vector where the names are the patterns to look for and the values are the replacement values (c(pattern1 = replacement1))

Details

str_replace_vec() is a vectorized form of stringr::str_replace().

This is different from passing a named vector to stringr::str_replace_all, which performs multiple replacements but to all pattern matches in a string.

See Also

Examples

Run this code
fruits <- c("two apples", "nine pears")
str_replace_vec(fruits, c("two" = "three", "nine" = "ten"))

Run the code above in your browser using DataLab