Sort
Start with the expanded example for each command. Open the variants for options and alternative R approaches. Read the qualifications before adapting the code.
gsort
Sort ascending and descending
Stata
gsort x1 -x2R Package:dplyr
arrange(data, x1, desc(x2))order
Move variables to the front
Stata
order x1-x4R Package:dplyr
relocate(data, x1:x4)1 more examples and alternatives
Move variables before another
Stata
order x1-x4, before(x5)R Package:dplyr
relocate(data, x1:x4, .before = x5)sort
Sort in ascending order
Stata
sort x1 x2R Package:dplyr
arrange(data, x1, x2)