`replace_first_match_col()` replaces the name of the column in `first_match_col()` with what the user inputs

replace_first_match_col(x, pattern, how = c("all", "any"), replace_with)

Arguments

x

A dataframe

pattern

A pattern to match

how

How to match the pattern (all or any)

replace_with

The name to replace the column name with

Value

dataframe with the replaced column name

Examples

data <- data.frame(a = c("a", "b", "c"), b = c("a", " ", "c"), c = c("a", "b", "1"))
replace_first_match_col(data, "\\D", "all", "new")
#>   new b c
#> 1   a a a
#> 2   b   b
#> 3   c c 1
replace_first_match_col(data, "\\d", "any", "new")
#>   a b new
#> 1 a a   a
#> 2 b     b
#> 3 c c   1