column: Extract Column Names Meeting Inclusion/Exclusion Criteria

View source: R/S03_Utilities.R

columnR Documentation

Extract Column Names Meeting Inclusion/Exclusion Criteria

Description

A function that matches or excludes column names in a data frame based on user-supplied sub-strings.

Usage

column(dtf, ...)

Arguments

dtf

A data frame.

...

Character strings with the sub-strings to match (or exclude) against the column names in dtf. If an entry starts with either !, ~, or -, any columns containing the substring will be excluded. Otherwise, the function will locate all column names containing all inputted sub-strings.

Value

A vector of column names meeting the inclusion and exclusion criteria.

Author(s)

Kevin Potter

Examples

# Create a data frame
dtf <- data.frame(
  IDS.INT.Subject = rep( 1:4, each = 2 ),
  SSS.CHR.Group = rep( c( 'A', 'A', 'B', 'B' ), each = 2 ),
  SSS.INT.Group = rep( c( 1, 1, 2, 2 ), each = 2 ),
  SSS.LGC.Group_A = rep( c( T, T, F, F ), each = 2 ),
  SSS.CHR.Time_point = rep( c( 'Pre', 'Post' ), 4 ),
  SSS.INT.Time_point = rep( 0:1, 4 ),
  OUT.DBL.Scores = rnorm( 8 )
)

#' # All variables containing 'SSS'
column( dtf, 'SSS' )

# All variables containing both 'SSS' and 'CHR'
column( dtf, 'SSS', 'CHR' )

# Variables containing 'SSS' but not 'CHR'
column( dtf, 'SSS', '~CHR' )


rettopnivek/arfpam documentation built on Oct. 20, 2024, 7:24 p.m.