Is there an stringr equivalent to base R's grep function?
I want to have the index of the string that matches. Example:
grep("F|Y", LETTERS)
[1] 6 25
With stringr my workaround would be using which as follows:
which(str_detect(LETTERS, "F|Y"))
[1] 6 25
Sorry for the late answer but it might be helpful for future visitors:
Now you can use str_which(string, pattern) which is a wrapper around which(str_detect(string, pattern)) and equivalent to grep(pattern, string).
str_which(LETTERS, "F|Y")
[1] 6 25
More details at: http://stringr.tidyverse.org/reference/str_subset.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With