If I have df like this
df <- read.table(text=\"
id date paid_at binded_at
1 107 2016-12-16 2017-06-02 2017-06-07
2
df %>%
select(id, paid_at, everything())
You can just select id
and paid_at
, and then add everything()
to select all other columns as well in their original order.
We can hardcode first three columns and then select the remaining ones with setdiff
.
cols <- c("paid_at", "id", "binded_at")
df[c(cols, setdiff(names(df), cols))]
# paid_at id binded_at date
#1 2017-06-02 107 2017-06-07 2016-12-16
#2 2017-06-02 107 2017-06-07 2017-11-27
#3 2017-06-02 107 2017-06-07 2017-11-28
#4 2017-01-01 109 2017-06-07 2016-11-28
#5 2017-01-01 109 2017-06-07 2017-11-29
#6 2018-01-01 110 2017-06-07 2017-12-04
With select
it can be similarly done
library(dplyr)
select(df, c(cols, setdiff(names(df), cols)))