Learn R Programming

Tivy (version 0.1.1)

find_column: Find column by pattern matching

Description

Searches for a column in a data frame using multiple pattern options. If multiple columns match, warns the user and returns the first match.

Usage

find_column(patterns, column_names, verbose = FALSE)

Value

Integer index of the first matching column, or NULL if no match found.

Arguments

patterns

Character vector of regex patterns to search for.

column_names

Character vector of column names to search in.

verbose

Logical. If TRUE, prints detailed matching information.

Examples

Run this code
cols <- c("codigo_faena", "numero_cala", "especie", "especies_capturadas")
species_patterns <- c("especie", "species", "sp")
col_index <- find_column(species_patterns, cols)

Run the code above in your browser using DataLab