Matching columns are columns whose names start with the given pattern and end with an incrementing integer.

get_matching_column_names(df, pattern)

Arguments

df

The dataframe from which to extract columns

pattern

The prefix of the column names to extract (string)

Value

A vector of strings that match the pattern

Examples

data <- data.frame(week_payment1 = c(1, 2, 3), week_payment2 = c(1, 2, 3),
                   week_payment3 = c(1, 2, 3), othercolumn = c(5, 6, 7))
get_matching_column_names(data, "week_payment")
#> [1] "week_payment1" "week_payment2" "week_payment3"