It is possibly to achieve this with base-r, by using a regex expression.
As I happen to favour working with the tidyverse approach, I still recommend to have a look at section 5.4 of the R for Data Science book, where selecting columns based on pattern matching is introduced.
There are a number of helper functions you can use within select() :
-
starts_with("abc") : matches names that begin with “abc”.
-
ends_with("xyz") : matches names that end with “xyz”.
-
contains("ijk") : matches names that contain “ijk”.
-
matches("(.)\\1") : selects variables that match a regular expression. This one matches any variables that contain repeated characters. You’ll learn more about regular expressions in strings.
-
num_range("x", 1:3) : matches x1 , x2 and x3 .
See ?select for more details.
If you're still struggling, please provide more detailed information on the column names and which one you're trying to select. Then we're able to help in constructing the right pattern and solution in either base-r or tidyverse.