select: Select a portion of a matrix based on a regular expression of...

Description Usage Arguments Details Value Examples

View source: R/manip.R

Description

Extract a subset of a matrix based on regex patterns on either the rownames, the colnames or both. Once this subset has been selected, assignments can be made following standard consistency rules.

Usage

1
select(m, row.pat = NULL, col.pat = NULL, ...)

Arguments

m

A matrix from which to select a subset

row.pat

A regular expression to use for rownames

col.pat

A regular expression to use for colnames

...

Additional arguments to pass to grep

Details

Oftentimes it is useful to get at a specific subset of data within a matrix. In large matrices, it can be cumbersome to access specific rows and/or columns using traditional subsetting methods, particularly if it is a complex set that is to be extracted. select provides regex searching on named matrices to access portions of a matrix that satisfy the regex. Note that select will work for data.frames as well.

It is possible to assign values to the selected subset as a means to modify the original matrix. Standard consistency rules must be satisfied for any assignment operations.

Value

A matrix containing all rows and columns that satisfy the patterns given. If no values match, then an empty matrix will be returned.

Examples

1
2
3
4
5
6
7
8
library(datasets)
select(swiss, "Rive")

select(swiss, col.pat="E", fixed=TRUE)

select(swiss, row.pat='^[A-T]', col.pat="^E")

select(swiss, "Rive", "Ed") <- min(select(swiss, "^[^R]", "Ed"))

zatonovo/futile.matrix documentation built on May 4, 2019, 9:11 p.m.