The dataset I am working on looks like this
a b vara_1 vara_2 vara_3 vara_4 vara_5 .... varb_1 varb_2 varb_3 varb_4
-----------------------------------------------------------------------------
100 120 a b c d e w x y z
I would like to change the column order of a dataset according to this particular order generated by the paste0 function:
> paste0(c("vara_", "varb_"),rep(1:10, each=2))
[1] "vara_1" "varb_1" "vara_2" "varb_2" "vara_3" "varb_3" "vara_4" "varb_4" "vara_5" "varb_5"
[11] "vara_6" "varb_6" "vara_7" "varb_7" "vara_8" "varb_8" "vara_9" "varb_9" "vara_10" "varb_10"
so the final look of the dataset would become
a b vara_1 varb_1 vara_2 varb_2 vara_3 varb_3 ....
-----------------------------------------------------------------------------
100 120 a w b x c y ....
is there anyway to put this into a format readable by tidyverse's select() function?
I have tried
condition <- paste0(c("vara_", "varb_"),rep(1:10, each=2)
data <- data %>% select(a, b, condition)
and also data <- data %>% noquote(select(a, b, condition)) with no luck.
Is the approach of listing out all the variable/ column orders possible for select()? Any help or alternative way of achieving the same goal is appreciated!