Just don't put [] after df and it will do what you need ...
df <- data.frame(x=1:2, y = 3:4, z = 5:6) df <- df[c("z", "y", "x")] df # zyx #1 5 3 1 #2 6 4 2
And if you doubt why, Pierre Lafortunโs comment is right.
as an additional note, I would also like to add a comma to a separate size:
df <- df[,c("z", "y", "x")]
I think this is more correct.
source share