matchcols: Select columns names matching certain critera

Description Usage Arguments Value Author(s) See Also Examples

View source: R/matchcols.R

Description

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

Usage

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

Arguments

object

Matrix or dataframe

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# create a matrix with a lot of 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 May 2, 2019, 5:49 p.m.