When grepl() should be used?

grepl() should be used for filtering rows in a data frame that contains a particular string.

Example: In this example, we have filtered rows based on the strength value 75.

R




library(dplyr)
  
# creating a data frame
df <- data.frame(Department = c('CSE', 'IT', 'ECE'
                                'EE', 'ME'),
                 Strength = c(80, 75, 75, 65, 70),
                 Score = c(75, 70, 65, 60, 60))
  
# filter rows that contain the string
# 75 in the Strength column
df %>% filter(grepl(75, Strength))


Output:



Difference Between grep() vs. grepl() in R

In this article, we will discuss the difference between grep() and grepl() in R programming language.

Similar Reads

grep()

This grep() function in R Language allows programmers to search for a match of a particular pattern in the given collection of strings. The syntax is given below,...

grepl()

...

Difference between grep() and grepl()

...

When grep() should be used?

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....

When grepl() should be used?

...