Learn R Programming

sos (version 2.1-8)

grepFn: Match pattern in a column of a matrix or data.frame

Description

Search for pattern in a column of a matrix or data.frame using grep. If value = TRUE (the default), return the selected subset of x.

Usage

grepFn(pattern, x, column='Function', ignore.case=FALSE,
       perl=FALSE, value=TRUE, fixed=FALSE,
       useBytes=FALSE, invert=FALSE)

Value

If(value) return an object of the same class as x containing those rows of x with x[, column] matching

pattern.

Else, return an integer vector identifying the rows of x with

x[, column] matching pattern.

Arguments

x

a matrix or data.frame containing a column named column.

pattern, ignore.case, perl, fixed, useBytes, invert

as for grep

column

character string giving the column of x in which to search for pattern.

value

logical: If TRUE, return the selected subset of x. If FALSE, return the row numbers returned by grep.

Author

Spencer Graves, Sundar Dorai-Raj

Details

1. g <- grep(pattern, x[, column])

2. if(value)return(x[g, ]) else return(g)

See Also

findFn grep

Examples

Run this code
z <- cbind(a=1:2, Function=c('s', 'spline'))
z. <- grepFn("spline", z)

stopifnot(
all.equal(z., z[2,,drop=FALSE])
)

Run the code above in your browser using DataLab