which_pattern: Which regex pattern first matches string

Description Usage Arguments Value Examples

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 if no match found.

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/amxtra documentation built on May 17, 2019, 12:01 p.m.