str_detect | R Documentation |
Vectorised over string
and pattern
, though using vectorised
patterns is relatively slow compared to stringr
.
Equivalent to grepl(pattern, x)
.
See str_which()
for an equivalent to grep(pattern, x)
.
str_detect(string, pattern, negate = FALSE)
string |
|
pattern |
|
negate |
|
Returns a logical vector
the same length as string
.
fruit <- c("apple", "banana", "pear", "pineapple") str_detect(fruit, "a") str_detect(fruit, "^a") str_detect(fruit, "a$") str_detect(fruit, "b") str_detect(fruit, "[aeiou]") # Also vectorised over pattern str_detect("aecfg", letters) # Returns TRUE if the pattern do NOT match str_detect(fruit, "^p", negate = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.