Q:

Pull specific column to beginning after columns have been ordered alphabetically

I have a dataframe in R. I'm ordering the columns alphabetically like this:
df_ordered <- df[,order(names(df))]

Now I want to select a specific column by name (column name is "city") and "pull" it to the front while leaving the rest unchanged, i.e. if the columns are:
alpha, beta, city, delta

I want them to be 
city, alpha, beta, delta

Thanks for your help.

A:

Using @nrussell sample Df data.frame, you can also do a trick with relevel.
Df[, levels(relevel(factor(names(Df)),"G"))]

We use the implicit sorting of factor() and use relevel to bring a particular column forward.

