chr.grep: Multiple Pattern Matching

View source: R/chr.grep.R

chr.grepR Documentation

Multiple Pattern Matching

Description

This function searches for matches to the character vector specified in pattern within each element of the character vector x.

Usage

chr.grep(pattern, x, ignore.case = FALSE, perl = FALSE, value = FALSE,
         fixed = FALSE, useBytes = FALSE, invert = FALSE, check = TRUE)

chr.grepl(pattern, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE,
          useBytes = FALSE, check = TRUE)

Arguments

pattern

a character vector with character strings to be matched.

x

a character vector where matches are sought.

ignore.case

logical: if FALSE (default), the pattern matching is case sensitive and if TRUE, case is ignored during matching.

perl

logical: if TRUE Perl-compatible regexps are used.

value

logical: if FALSE (default), a vector containing the (integer) indices of the matches determined by grep is returned, and if TRUE, a vector containing the matching elements themselves is returned.

fixed

logical: if TRUE, pattern is a string to be matched as is. Overrides all conflicting arguments.

useBytes

logical: if TRUE, the matching is done byte-by-byte rather than character-by-character. See ‘Details’.

invert

logical: if TRUE, function returns indices or values for elements that do not match.

check

logical: if TRUE (default), argument specification is checked.

Value

Returns a integer vector with the indices of the mathces when value = FALSE, character vector containing the matching elements when value = TRUE, or a logical vector when using the chr.grepl function.

Author(s)

Takuya Yanagida

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole

See Also

chr.gsub, chr.omit, chr.trim

Examples

chr.vector <- c("James", "Mary", "Michael", "Patricia", "Robert", "Jennifer")

# Example 1: Indices of matching elements
chr.grep(c("am", "er"), chr.vector)

# Example 2: Values of matching elements
chr.grep(c("am", "er"), chr.vector, value = TRUE)

# Example 3: Matching element?
chr.grepl(c("am", "er"), chr.vector)

misty documentation built on June 29, 2024, 9:07 a.m.

Related to chr.grep in misty...