cgrep: a function to select columns by 'regex'

Description Usage Arguments Value See Also Examples

Description

Select columns (or rows) by 'perl' regular expression. See regex{base} for 'regex' documenation. 'regex' is a very powerful grammar to match strings.

Usage

1
cgrep(x, pattern, dim = c("c", "r"))

Arguments

x

A dataframe, list a matrix with column names or a named numeric.

pattern

A search string

dim

A character either "c" for selection of columns or "r" for selection of rows, if x is a list this parameter has no meaning

Value

A Dataframe, list or matrix where the column- or row names match the pattern. By default the selecion is by column, unless the dim parameter specifies "r" for rows. If f x is not a dataframe and if a single column or row is selected 'R' will flatten the results to a vector.

See Also

regex{base}

Examples

1
2
3
4
5
6
7
8
9
 head(cgrep(iris, "^.+$")) # matches all columns that have non-empty column names and thus
 #drops all columns with empty names

 head(cgrep(iris, "^Petal\\.")) # matches all columns that have  names starting with the
 #string "Petal."
 head(cgrep(iris, "\\.")) # columns with names that contain a dot
 head(cgrep(iris, "\\.[Ww]idth$")) # columns with names ending in the string ".width" or ".Width".
 head(cgrep(iris, "^[SP]e.al")) # columns that have names starting with either capital
 #'S' or 'P' then an 'e' followed by any character and then 'al'

1na/colr documentation built on May 5, 2019, 10:41 a.m.