Reorder columns in R

I got the need to reorder the column order or a data frame in R and after searching a little, I've found a very easy way to do it.

Having a data frame named test like

a b c d e
[1,] 1 11 21 31 41
[2,] 2 12 22 32 42
[3,] 3 13 23 33 43
[4,] 4 14 24 34 44
[5,] 5 15 25 35 45

all that is required is to reassign the data frame using a new column order, like

new_column_order <- c("b", "c", "a", "e", "d")

test <- test[,new_column_order]

And that solves the problem.

This seems to work both with a data frame and a matrix.

./M6