match_part: Partial string matching and replacing

Description Usage Arguments Value Examples

View source: R/tools.R

Description

Partial string matching and replacing

Partial string matching and replacing

Usage

1
2
3

Arguments

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

Value

A list of indices of partial matches

Character vector with replaced values

Examples

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")

tjebo/tjebtools documentation built on Nov. 15, 2021, 11:21 p.m.