column_find: column_find

View source: R/column_find.R

column_findR Documentation

column_find

Description

Identifies or extracts columns in a dataframe using a string.

Usage

column_find(pattern, data, return = "logical", invert = FALSE, antipattern)

Arguments

pattern

a character string that is used to find the columns of interest. It can be a regular expression.

data

a data frame.

return

a string specifying the output desired. "logical" (the default) returns a logical vector with TRUE indicating that a column name includes the pattern. "numeric" returns a numeric vector that identifies the column numbers matching the pattern. "character" returns a character vector with the column names that match the pattern. "data.frame" returns a data frame that includes only those columns whose names match the pattern.

invert

if TRUE, identifies or extracts columns that DO NOT match the pattern.

antipattern

an optional character string that is used to identify columns that should not be returned. It can be a regular expression.

Examples

x <- data.frame(my_column_x  = 1:10,
                my_column_x2 = 1:10 * rnorm(10, mean = 1),
                my_column_x3 = 1:10 * rnorm(10, mean = 1),
                my_column_y  = 11:20,
                my_column_y2 = 11:20 * rnorm(10, mean = 1),
                my_column_y3 = 11:20 * rnorm(10, mean = 1))

column_find(pattern = "x", data = x, return = "logical")
column_find(pattern = "x", data = x, return = "numeric")
column_find(pattern = "x", data = x, return = "character")
column_find(pattern = "x", data = x, return = "data.frame")


camkay/panoply documentation built on Jan. 17, 2025, 6:31 a.m.