Function to get a logical vector if a text contains one of multiple sting patterns
Source:R/filter.R
hasOneOfMultiplePatterns.RdFunction to get a logical vector if a text contains one of multiple sting patterns
Examples
# define a vector of patterns
patterns <- c("Merc", "Hornet")
# create a DF
df <- datasets::mtcars
df$car <- rownames(df)
# filter the DF to keep only the rows that do not contain one of the patterns
df_with_pattern <- df %>% dplyr::filter(hasOneOfMultiplePatterns(patterns, df$car))
# filter the DF to keep only the rows that do not contain one of the patterns
df_without_pattern <- df %>% dplyr::filter(!hasOneOfMultiplePatterns(patterns, df$car))