recodeMatches: Recode values of variable/factor matching patterns

Description Usage Arguments Details Value Author(s) See Also

View source: R/merge_utils.R

Description

Recode values of variable/factor matching patterns

Usage

1
2
recodeMatches(x, patterns, targets, default = NULL, keep.na = TRUE,
  ignore.case = TRUE, ignore.punc = TRUE, ...)

Arguments

x

The character vector/factor to recode.

patterns

List of regular expressions for matching.

targets

Values to recode corresponding matches in 'patterns' into.

default

Default target value for those values of x that don't match any pattern. When default=NULL, non-matching values of x will be kept in the output.

keep.na

If TRUE then NA's in x will be retained in the output.

ignore.case

If TRUE (default) then matching is not case sensitive.

ignore.punc

If TRUE (default) then punctuation will be ignored when matching.

...

optional arguments to grepl (e.g. use fixed=TRUE for string instead of regexp matching)

Details

This function is like 'recodeVar' except that it uses regular expressions to match the source variables (using 'grepl'). For each unique value of 'x' the regexps in 'patterns' are tried in turn until a match is found, then the corresponding element of 'targets' is used to recode the value. If length(patterns) > length(targets) then the final target will be used for all excess patterns. The 'default' and 'keep.na' parameters are the same as for 'recodeVar'. To do string matching instead of regular expression matching use fixed=TRUE

Value

A vector

Author(s)

Ben Veal

See Also

recode for recoding numbers (in library(car)), recodeVar, recodeAs, colwise2 for recoding multiple dataframe columns simultaneously (in library(plyr)).


vapniks/mergeutils documentation built on May 3, 2019, 4:33 p.m.