str_locate | R Documentation |
Vectorised over string
and pattern
, though using vectorised
patterns is relatively slow compared to stringr
. If the match is of length
0, (e.g. from a special match like $
) end will be one character less
than start.
str_locate(string, pattern) str_locate_all(string, pattern)
string |
|
pattern |
|
For str_locate()
, an integer matrix
. First column gives start
postion of match, and second column gives end position. For
str_locate_all()
a list
of integer matrices.
str_extract()
for a convenient way of extracting matches.
fruit <- c("apple", "banana", "pear", "pineapple") str_locate(fruit, "$") str_locate(fruit, "a") str_locate(fruit, "e") str_locate("apple", c("a", "b", "p", "p")) str_locate_all(fruit, "a") str_locate_all(fruit, "e") # Find location of every character str_locate_all(fruit, "")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.