stringr (version 0.6.1)

str_sub_replace: Replace substrings in a character vector. str_sub<- will recycle all arguments to be the same length as the longest argument.

Description

Replace substrings in a character vector. str_sub<- will recycle all arguments to be the same length as the longest argument.

Usage

str_sub(string, start = 1L, end = -1L) <- value

Arguments

string
input character vector.
start
integer vector giving position of first charater in substring, defaults to first character. If negative, counts backwards from last character.
end
integer vector giving position of last character in substring, defaults to last character. If negative, counts backwards from last character.
value
replacement string

Value

  • character vector of substring from start to end (inclusive). Will be length of longest input argument.

Examples

Run this code
x <- "BBCDEF"
str_sub(x, 1, 1) <- "A"; x
str_sub(x, -1, -1) <- "K"; x
str_sub(x, -2, -2) <- "GHIJ"; x
str_sub(x, 2, -2) <- ""; x

Run the code above in your browser using DataLab