Learn R Programming

wrappedtools (version 0.9.7)

ColSeeker: Find numeric index and names of columns based on class(es) and patterns

Description

ColSeeker looks up colnames (by default for tibble rawdata) based on type and parts of names, using regular expressions. Be warned that special characters as e.g. [ ( need to be escaped or replaced by . Exclusion rules may be specified as well.

Usage

ColSeeker(
  data = rawdata,
  namepattern = ".",
  varclass = NULL,
  exclude = NULL,
  excludeclass = NULL,
  casesensitive = TRUE,
  returnclass = FALSE
)

Value

A list with index, names, backticked names, and count; optionally the classes as well

Arguments

data

tibble or data.frame, where columns are to be found; by default rawdata

namepattern

Vector of pattern to look for.

varclass

Vector, only columns of defined class(es) are returned

exclude

Vector of pattern to exclude from found names.

excludeclass

Vector, exclude columns of specified class(es)

casesensitive

Logical if case is respected in matching (default FALSE: a<>A)

returnclass

Logical if classes should be included in output

Examples

Run this code
ColSeeker(data = mtcars, namepattern = c("^c", "g"))
ColSeeker(data = mtcars, namepattern = c("^c", "g"), exclude = "r")
assign("rawdata", mtcars)
ColSeeker(namepattern = c("^c", "g"), varclass="numeric")
num_int_data <- data.frame(num1=rnorm(10), num2=runif(10), int1=1:10, int2=11:20)
ColSeeker(num_int_data, varclass="numeric")  # integers are not found
ColSeeker(num_int_data, varclass=c("numeric","integer")) 

Run the code above in your browser using DataLab