Skip to contents

This function checks for the presence of potential column names within a data frame and returns the first one that matches, or NA_character_ if none is found.

Usage

find_column_name(data, potential_names)

Arguments

data

A data frame or tibble.

potential_names

A character vector containing potential column names to search for.

Value

A string representing the first matching column name, or NA_character_ if none is found.

Examples

df <- data.frame(
  Barcode = 1:5,
  FreezerName = 6:10
)
find_column_name(df, c("Barcode", "Tube ID", "TubeCode"))
#> [1] "Barcode"
find_column_name(df, c("FreezerName", "FreezerName"))
#> [1] "FreezerName"