Skip to content

Instantly share code, notes, and snippets.

@kleinlennart
Last active January 27, 2021 20:50
Show Gist options
  • Save kleinlennart/9c824b6152ac6df033dfb137572be81e to your computer and use it in GitHub Desktop.
Save kleinlennart/9c824b6152ac6df033dfb137572be81e to your computer and use it in GitHub Desktop.
R Sort Columns alphabetically
# Sort all columns alphabetically
dat <- dat[,order(colnames(dat))]
dat <- dat %>% select(sort(current_vars())) # Alternatively
# Reorder each column alphabetically
dat <- map_df(dat, function(x) {sort(x, na.last = TRUE)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment