We can use do.call
with order
for ordering on all the columns of a dataset
DF[do.call(order, DF),]
If we use tidyverse
, there is arrange_at
that will take column names
library(dplyr)
DF %>%
arrange_at(vars(names(.)))
#or as @Sotos commented
#arrange_all()
#or
#arrange(!!! rlang::syms(names(.)))
# A B C D
#1 11 2 432 4
#2 11 3 432 4
#3 13 4 241 5
#4 42 5 2 3
#5 51 5 332 1
#6 51 5 332 1
#7 51 5 332 2