substri: Extract substrings between delimiters by position

View source: R/substri.R

substriR Documentation

Extract substrings between delimiters by position

Description

substri() splits each element in 'x' into substrings and returns the desired substring(s). 'sep' defines the delimiters separating the strings into substrings, such that the input data between the matches become the fields themselves. 'pos' defines the substring index(es) to be returned.

Usage

substri(x, sep = "\\.|-|_", pos = 1, max.nchar = NULL, na.rm = TRUE)

Arguments

x

A character vector.

sep

The pattern to split each element of 'x' by. Default: '\.|-|_'

pos

The substring index(es) to be returned. Default: 1

max.nchar

'NULL', or a maximum number of characters that the substrings should be trimmed to contain. Default: NULL

na.rm

Remove NA substring positions. Default: TRUE

Value

A character vector containing the extracted substrings.

See Also

str_split,str_replace_all

Examples

## Not run: 
x = c('dog.cat.mat', 'dog_frog')
substri(x)
substri(x, pos = 2)
substri(x, pos = c(1,3))
substri(x, pos = c(1,3), na.rm = FALSE)
substri(x, sep = "-")

## End(Not run)

jlaffy/scalop documentation built on April 13, 2025, 7:34 a.m.