column_combine: column_combine

View source: R/column_combine.R

column_combineR Documentation

column_combine

Description

Creates a composite column using only columns in a data frame that have names that match a pattern.

Usage

column_combine(
  pattern,
  data,
  fun = mean,
  verbose = FALSE,
  message = TRUE,
  invert = FALSE
)

Arguments

pattern

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

data

a data frame.

fun

the function to use to create the composite column; defaults to 'mean'.

verbose

specifies whether all column names should be listed, regardless of length.

message

if TRUE, messages are generated telling the user which columns were used to create the composite.

invert

if TRUE, combines columns that DO NOT match the pattern.

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_combine(pattern = "x", data = x)
column_combine(pattern = "_y", data = x)
column_combine(pattern = "my_column", data = x)

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