str_detect()
Function in R Language is used to check if the specified match of the substring exists in the original string. It will return TRUE for a match found otherwise FALSE against each of the element of the Vector or matrix.
Note: This function uses 'stringr' Library.
Syntax: str_detect(string, pattern)
Parameter:
string: specified string
pattern: Pattern to be matched
Example 1:
library(stringr)
x < - c( "Geeks" , "Hello" , "Welcome" , "For" )
pat < - "Geeks"
str_detect(x, pat)
|
Output:
[1] TRUE FALSE FALSE FALSE
Example 2:
library(stringr)
x1 < - c( "Geeks" , "Geeks" , "Welcome" , "Geeks" )
x2 < - c( "Geeks" , "Hello" , "Geeks" )
result < - array(c(x1, x2), dim = c( 2 , 2 , 2 ))
pat < - "Geeks"
result
str_detect(result, pat)
|
Output:
,, 1
[, 1] [, 2]
[1, ] "Geeks" "Welcome"
[2, ] "Geeks" "Geeks",, 2
[, 1] [, 2]
[1, ] "Geeks" "Geeks"
[2, ] "Hello" "Geeks"
[1] TRUE TRUE FALSE TRUE TRUE FALSE TRUE TRUE