Count or Identify Matches of a Pattern in a Vector
count_matching_elements.RdThis function counts the number of elements in a vector that contain a given pattern, or returns a logical vector indicating which elements match the pattern.
Value
An integer representing the number of matches if return is "count", or a logical vector indicating which elements match the pattern if return is "logi".
Examples
vec <- c("abc", "def", "xyz", "abcd")
count_matching_elements(vec, "abc", return = "count") # Returns 2
#> [1] 2
count_matching_elements(vec, "abc", return = "logi") # Returns c(TRUE, FALSE, FALSE, TRUE)
#> [1] TRUE FALSE FALSE TRUE