I am wanting to order my columns of a data frame by string matches.
library(dplyr)
data <- data.frame(start_a = 1,
start_f = 3,
end_a = 5,
end_f = 7,
middle_a= 9,
middle_f = 11)
- For example I want to select
start_f, start_a, middle_f, middle_a, end_f ,end_a - I am attempting to do so with
data %>% select(matches("(start|middle|end)_(f|a)"))), so that the order I have typed within the matches is the order that I want the columns to be selected. - Desired output would be
data[c(2,1,6,5,4,3)]