Using the following example dataframe:
a <- c(1:5) b <- c(\"Cat\", \"Dog\", \"Rabbit\", \"Cat\", \"Dog\") c <- c(\"Dog\", \"Rabbit\", \"Cat\", \"Do
To generalize the reshuffling of columns in any order using dplyr, for example, to reshuffle:
dplyr
df <- data.frame(a,b,c,d,e,f)
to
df[,c("a","d","e","f","b","c")] df %>% select(a, d:f, b:c)