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.

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.

Examples

if (FALSE) {
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 = "-")
}