Learn R Programming

Kmisc (version 0.4.0-1)

extract_rows.re: Extract Rows from a Data Frame / Matrix Based on Regex Matching

Description

This function extracts rows from a data frame / matrix x for all rows matching the regex pattern supplied.

Usage

extract_rows.re(x, regex, match_var = rownames(x),
    perl = TRUE, ...)

Arguments

x
a data frame / matrix with row names.
regex
a regular expression to evaluate against the row names.
match_var
the variable to match on. defaults to rownames(x).
perl
boolean. use perl-compatible regular expressions?
...
optional arguments passed to grep.

Examples

Run this code
dat <- data.frame( x=letters, y=LETTERS )
rownames(dat) <- 1:26
## get all rows in dat with a 1, 2, 3 or 4 in the name
extract_rows.re( dat, "[1-4]" )

Run the code above in your browser using DataLab