Description Usage Arguments Value Examples
Partial string matching and replacing
Partial string matching and replacing
1 2 3 | match_part(x, table)
match_replace(x, replace, no_match = NA_character_)
|
x |
Vector. Values to be matched |
table |
Vector. characters to be matched against |
replace |
Vector of new labels if a partial match is found. If named vector, names are used. If more than one match is found, the last match will replace the original value. |
no_match |
if there is no partial match |
A list of indices of partial matches
Character vector with replaced values
1 2 3 4 5 6 7 8 9 | oceans <- c("pacific", "atlantic", "indian", "mediterranean")
oceans_long <- c("Eastern Central Atlantic", "Eastern Central Pacific", "Eastern Indian Ocean",
"Mediterranean and Black Sea", "Northeast Central Atlantic",
"Northeast Pacific", "Northwest Central Atlantic", "Northwest Pacific",
"Southeast Central Atlantic", "Southeast Pacific", "Southwest Atlantic",
"Southwest Pacific", "Western Central Atlantic", "Western Central Pacific",
"Western Indian Ocean", "World", "Atlantic Pacific")
match_replace(oceans_long, oceans, "Other")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.