Skip to content

Instantly share code, notes, and snippets.

@rhilfi
Created December 31, 2019 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhilfi/7d1b35958a638136635c5d64f9977ad9 to your computer and use it in GitHub Desktop.
Save rhilfi/7d1b35958a638136635c5d64f9977ad9 to your computer and use it in GitHub Desktop.
putLastColumnFirst #R #dplyr
## adapted from: https://stackoverflow.com/questions/22286419/move-a-column-to-first-position-in-a-data-frame
## see also: https://stackoverflow.com/questions/37171891/how-does-dplyrs-select-helper-function-everything-differ-from-copying
# create data.frame to illustrate
a<-1:5
b<-a
c<-as.character(b)
df<-as.data.frame(cbind(a,b,c))
# end create data.frame to illustrate
df
# move last column to first place
df_r<-select(df,c,everything())
df_r
# works also in a pipe
df_r2<-df %>%
select(c,everything())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment