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.