Learn R Programming

genomes (version 2.16.0)

like: Pattern matching using wildcards

Description

Pattern matching using wildcards

Usage

x %like% pattern

Arguments

pattern
character string containing the pattern to be matched
x
values to be matched

Value

A logical vector indicating if there is a match or not. This will mostly be useful in conjunction with the subset function.

Details

Only wildcards matching a single character '?' or zero or more characters '*' are allowed. Matches are case-insensitive. The pattern is first converted to a regular expression using glob2rx then matched to values in x using grep.

This is a shortcut for a commonly used expression found in the subset example where nm %in% grep("^M", nm, value=TRUE) simplifies to nm %like% 'M*'.

See Also

grep, glob2rx, subset

Examples

Run this code
data(proks)
subset(proks, name %like% 'Yersinia*', c(name, released))
# also works with date or numeric fields
subset(proks, released %like% '2008-01*', c(name, released))

Run the code above in your browser using DataLab