Learn R Programming

Causata (version 4.2-0)

GrepLoop: Searches for a list of patterns within a list of strings.

Description

Given a vector of patterns and a vector of strings, this searches for the patterns within the strings and returns the matching locations.

Usage

GrepLoop(patternVec, x, ignore.case=TRUE, boolean=FALSE)

Arguments

patternVec
A vector of pattern strings to search for.
x
A vector of strings to search through using grep.
ignore.case
Indicates if the matches are case-sensitive.
boolean
Controls whether an index of integers or booleans is returned.

Value

A vector of indices indicating which elements in x match any of the patterns in patternVec.

Details

This function applies grep multiple times.

See Also

grep.

Examples

Run this code
pats <- c("gray", "grey")
x <- c("dark gray", "yellow", "light grey", "red")
# The first and third elements in x match the patterns
GrepLoop(pats, x)

Run the code above in your browser using DataLab