replace_string: Replace String Contents

View source: R/S03_Utilities.R

replace_stringR Documentation

Replace String Contents

Description

Function that replaces a specified pattern found within a string (or vector of strings) with a user-specified pattern.

Usage

replace_string(s, to_replace, replace_with = "")

Arguments

s

A character vector.

to_replace

A character vector, the patterns to match and replace within each string.

replace_with

An optional character vector, either of length one or of matching length to to_replace, the patterns to substitute.

Value

A character string.

Examples

# Example string
x <- c( 'AA', 'AB', 'AC', 'DD' )
# Remove the letter 'A'
replace_string( x, 'A' )
# Replace the letter 'A' with '1'
replace_string( x, 'A', '1' )
# Replace multiple letters
replace_string( x, c( 'B', 'C' ), c( '1', '2' ) )


rettopnivek/arfpam documentation built on Oct. 20, 2024, 7:24 p.m.