R Utilities: Vector Based Version of grep

Description

This function imitates the usage of grep but it is extended to a vector argument.

Usage

1
grep.vec(pattern.vec, x, operator="AND")

Arguments

pattern.vec

String which should be looked for in vector x

x

A character vector

operator

An optional string. The default argument "AND" searches all entries in x which contain all elements of pattern.vec. If operator is different from the default, then the "OR" logic applies, i.e. the functions searches for vector entries which contain at least one of the strings in pattern.vec.

Author(s)

Alexander Robitzsch

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
vec <- c("abcd" , "bcde" , "aedf" , "cdf" )
# search for entries in vec with contain 'a' and 'f'
#  -> operator = "AND"
grep.vec( pattern.vec=c("a","f") , x=vec )
  ##   $x
  ##   [1] "aedf"
  ##   $index.x
  ##   [1] 3

# search for entries in vec which contain 'a' or 'f'
grep.vec( pattern.vec=c("a","f") , x=vec , operator="OR")
  ##   $x
  ##   [1] "abcd" "aedf" "cdf" 
  ##   $index.x
  ##   [1] 1 3 4

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.