substri | R Documentation |
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)
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 |
A character vector containing the extracted substrings.
str_split
,str_replace_all
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.