Learn R Programming

Ecfun (version 0.3-2)

pmatchIC: pmatch ignoring case

Description

pmatch with an additional ignoreCase argument, returning a name not an index like pmatch (and returning a name if supplied a number, unlike pmatch, which coerces the input to numeric).

Usage

pmatchIC(x, table, nomatch = NA_integer_, 
  duplicates.ok = FALSE, 
  ignoreCase=TRUE)

Value

A character vector of matches.

Arguments

x

the values to be matched. If is.numeric(x), pmatch2 returns table[x].

This is different from pmatch, which matches as.character(x).

Otherwise, if ignoreCase is TRUE, pmatchIC returns pmatch(tolower(x), tolower(table)).

table

the values to be matched against: converted to a character vector, per pmatch.

nomatch

the value to be returned at non-matching or multiply partially matching positions.

duplicates.ok

should elements be in table be used more than once? (See pmatch for an example.)

ignoreCase

logical: if TRUE and x is character, pmatchIC returns pmatch(tolower(x), tolower(table)).

Author

Spencer Graves

See Also

Examples

Run this code
yr <- pmatchIC('Yr', c('y1', 'yr', 'y2'))
stopifnot(
all.equal('yr', yr)
)

# integer
m2 <- pmatchIC(2, table=letters)
stopifnot(
all.equal(m2, 'b')
)

Run the code above in your browser using DataLab