matchcols: Select columns names matching certain critera

View source: R/matchcols.R

matchcolsR Documentation

Select columns names matching certain critera

Description

This function allows easy selection of the column names of an object using a set of inclusion and exclusion critera.

Usage

matchcols(object, with, without, method=c("and","or"), ...)

Arguments

object

Matrix or data frame

with, without

Vector of regular expression patterns

method

One of "and" or "or"

...

Optional arguments to grep

Value

Vector of column names which match all (method="and") or any (method="or") of the patterns specified in with, but none of the patterns specified in without.

Author(s)

Gregory R. Warnes greg@warnes.net

See Also

grep

Examples

# Create a matrix with many named columns
x <- matrix(ncol=30, nrow=5)
colnames(x) <- c("AffyID","Overall Group Means: Control",
                 "Overall Group Means: Moderate",
                 "Overall Group Means: Marked",
                 "Overall Group Means: Severe",
                 "Overall Group StdDev: Control",
                 "Overall Group StdDev: Moderate",
                 "Overall Group StdDev: Marked",
                 "Overall Group StdDev: Severe",
                 "Overall Group CV: Control",
                 "Overall Group CV: Moderate",
                 "Overall Group CV: Marked",
                 "Overall Group CV: Severe",
                 "Overall Model P-value",
                 "Overall Model: (Intercept): Estimate",
                 "Overall Model: Moderate: Estimate",
                 "Overall Model: Marked: Estimate",
                 "Overall Model: Severe: Estimate",
                 "Overall Model: (Intercept): Std. Error",
                 "Overall Model: Moderate: Std. Error",
                 "Overall Model: Marked: Std. Error",
                 "Overall Model: Severe: Std. Error",
                 "Overall Model: (Intercept): t value",
                 "Overall Model: Moderate: t value",
                 "Overall Model: Marked: t value",
                 "Overall Model: Severe: t value",
                 "Overall Model: (Intercept): Pr(>|t|)",
                 "Overall Model: Moderate: Pr(>|t|)",
                 "Overall Model: Marked: Pr(>|t|)",
                 "Overall Model: Severe: Pr(>|t|)")

# Get the columns which give estimates or p-values
# only for marked and severe groups
matchcols(x, with=c("Pr", "Std. Error"),
             without=c("Intercept","Moderate"),
             method="or")

# Get just the column which give the p-value for the intercept
matchcols(x, with=c("Intercept", "Pr"))

gdata documentation built on Oct. 22, 2024, 9:06 a.m.