mstrings | R Documentation |
Multiple patterns or values matching
mgrep(pat, x, na.rm, value) mmatch(pat, x, na.rm) mgrep_ext(pat, x, y, na.rm) mmatch_ext(pat, x, y, na.rm) mmatch_sub(pat, x, y, missing) mmatch(pat, x, na.rm = FALSE) mgrep_ext(pat, x, y = x, na.rm = TRUE) mmatch_ext(pat, x, y, na.rm = TRUE) mmatch_sub(pat, x, y, missing = NA)
pat |
atomic: pattern strings |
x |
atomic: target strings |
na.rm |
logical |
value |
logical |
y |
atomic: strings for extraction or substitution |
missing |
atomic: the default value is NA |
## Not run: # Multiple patterns matching x <- c("A,D", "E,F", "G,C", "C,H") p1 <- c("A", "B", "C", "D") p2 <- c("X", "Y") p3 <- "A" mgrep(p1, x) mgrep(p1, x, F, T) mgrep(p1, x, T, F) mgrep(p1, x, T, T) # If none of the patterns match, a list consisting of NAs or an empty list is returned. mgrep(p2, x) mgrep(p2, x, na.rm = T) # Return as a list even if there is only one pattern mgrep(p3, x) # Multiple values matching x <- c("A", "B", "C", "D", "B", "C", "D", "A", "B", "C") p4 <- c("A", "B", "C", "D", "X") p5 <- c("H", "J", "K") mmatch(p4, x) mmatch(p4, x, na.rm = T) mmatch(p5, x) mmatch(p5, x, na.rm = T) # Multiple values mathing and extract correspondig data. x <- c("A,D", "E,F", "G,C", "C,H") y <- c("v1", "v2", "v3", "v4") p <- c("A", "B", "C", "D") dat <- data.frame(x, y, stringsAsFactors = FALSE) mgrep_ext(p, dat$x, dat$y) # Multiple values matching and extract corresponding data. x <- c("A", "B", "C", "D", "B", "C", "D", "A", "B", "C") p <- c("A", "B", "C", "D", "X") y <- rpois(10, 5) dat <- data.frame(x, y, stringsAsFactors = FALSE) mmatch_ext(p, x, y) # Multiple values matching and substitute to corresponding values. x <- c("A", "B", "E", "C", "D", "F", "B", "C", "D", "G", "A", "B", "C") p <- c("A", "B", "C", "D", "X") y <- c("a", "b", "c", "d", "x") mmatch_sub(p, x, y, missing = NA) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.