Description Usage Arguments Value Examples
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.
1 | which_pattern(string, pattern)
|
string |
vector of strings to match against patterns |
pattern |
vector of patterns to match strings |
Numeric index of the pattern to first match each string or NA if no match found.
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.