Description Usage Arguments Value See Also Examples
For each element in the string
vector, this function finds the name (or number)
of a collection of regex patterns — "band" — one of which was the first to match
the string element. Order of bands in the bandlist
influences the results.
The function is useful when classifying character variables based on content.
1 |
string |
vector of strings to match against patterns |
bandlist |
list of pattern bands: <name> = <vector of applicable patterns> |
as.factor |
if FALSE, return band names, not factors; otherwise if TRUE |
Vector of strings (or factors) of pattern "bands" that matched each string first, numeric pattern index if no band names given.
which_pattern()
for the underlying pattern matching behaviour.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # In the following examples patterns should match as narrow as possible
# because the first match wins.
seasons <- list(
Wi = c("De", "Ja", "Fe"),
Sp = c("Ma", "Ap"),
Su = c("Ju", "Au"),
Au = c("Se", "Oc", "No")
)
patband(month.name, seasons, as.factor = TRUE)
# [1] Wi Wi Sp Sp Sp Su Su Su Au Au Au Wi
# Levels: Wi Sp Su Au
quarters <- list(
c("Ja", "Fe", "Mar"),
c("Ap", "May", "Jun"),
c("Jul", "Au", "Se"),
c("Oc", "No", "De")
)
patband(month.name, quarters)
# [1] 1 1 1 2 2 2 3 3 3 4 4 4
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.