str_elem: Extract a single character from a string, using its index.

View source: R/elem.R

str_elemR Documentation

Extract a single character from a string, using its index.

Description

If the element does not exist, this function returns the empty string. This is consistent with stringr::str_sub(). This function is vectorised over both arguments.

Usage

str_elem(string, index)

Arguments

string

A character vector.

index

An integer. Negative indexing is allowed as in stringr::str_sub().

Value

A one-character string.

See Also

Other single element extractors: str_elems(), str_paste_elems()

Examples

str_elem(c("abcd", "xyz"), 3)
str_elem("abcd", -2)

strex documentation built on Nov. 2, 2023, 6:04 p.m.