grepl()
This grepl() function in the R language returns the value True if the specified pattern is found in the vector and false if it is not found.
The syntax is given below,
Syntax: grepl(stringPattern, string, ignore.case=FALSE)
Parameters:
- stringPattern: The string pattern to be searched
- string: character vector on which searching to be performed
- ignore.case: whether to ignore case in the search. Here ignore.case is an optional parameter as is set to FALSE by default.
Example 1:
R
# R program to illustrate # grepl function # Initializing a string vector str <- c ( "w3wiki" , "Bhuwanesh" , "Nainwal" , "gfg" ) # Calling grepl() function grepl ( "w3wiki" , str) grepl ( "Bhuwanesh" , str) grepl ( "gfg" , str) grepl ( "Nainwal" , str) |
Output:
Example 2:
R
# R program to illustrate # grepl function # Creating string vector x <- c ( "w3wiki" , "Bhuwanesh" , "Nainwal" , "gfg" ) # Calling grepl() function grepl ( "gfg" , x, ignore.case = TRUE ) grepl ( "Bhuwanesh" , x, ignore.case = TRUE ) grepl ( "w3wiki" , x, ignore.case = TRUE ) grepl ( "Nainwal" , x, ignore.case = TRUE ) |
Output:
Difference Between grep() vs. grepl() in R
In this article, we will discuss the difference between grep() and grepl() in R programming language.