which_pattern: Which regex pattern first matches the string

Description Usage Arguments Value Examples

View source: R/which_pattern.R

Description

For each element in the string vector, this function finds which pattern is the first to match it using grepl. Thus pattern order influences the results.

Usage

1

Arguments

string

vector of strings to match against patterns

pattern

vector of patterns to match strings

Value

Numeric index of the pattern to first match each string or NA

Examples

1
2
3
4
5
which_pattern(month.name, c("^J", "[A,a]", "[O,o]"))
# [1]  1  2  2  2  2  1  1  2 NA  3  3 NA

which_pattern(month.name, c("[A,a]", "^J", "[O,o]"))
#[1]  1  1  1  1  1  2  2  1 NA  3  3 NA

avidclam/avidstart documentation built on May 17, 2019, 10:01 a.m.