I want to select multiple columns based on their names with a regex expression. I am trying to do it with the piping syntax of the dplyr
package. I che
You can use matches
mtcars %>%
select(matches('m|ar')) %>%
head(2)
# mpg am gear carb
#Mazda RX4 21 1 4 4
#Mazda RX4 Wag 21 1 4 4
According to the ?select
documentation
‘matches(x, ignore.case = TRUE)’: selects all variables whose name matches the regular expression ‘x’
Though contains
work with a single string
mtcars %>%
select(contains('m'))