Created
December 31, 2019 15:27
-
-
Save rhilfi/7d1b35958a638136635c5d64f9977ad9 to your computer and use it in GitHub Desktop.
putLastColumnFirst #R #dplyr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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