pmatch()
function in R Language is used to seek match for the pattern passed as argument. It returns the strings that begin with the pattern being searched.
Syntax: pmatch(pat, string, nomatch)
Parameters:
pat: pattern vector to be searched
string: vector to be matched
nomatch: return when no match is found
Example 1:
x < - c( "Geeks" , "Books" , "geek" )
x
pmatch( "gee" , x)
pmatch( "Boo" , x)
|
Output:
[1] "Geeks" "Books" "geek"
[1] 3
[1] 2
Example 2:
x < - c( "Geeks" , "Books" , "geek" )
x
pmatch(c( "Gee" , "Boo" , "re" ), x, nomatch = - 1 )
|
Output:
[1] "Geeks" "Books" "geek"
[1] 1 2 -1