Skip to contents

Function to get a logical vector if a text contains one of multiple sting patterns

Usage

hasOneOfMultiplePatterns(patterns, text)

Arguments

patterns

A vector of strings to detect in the text

text

A vector of strings to detect the patterns

Value

A logical vector of the same length as the text vector

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