Last active
March 10, 2019 23:23
-
-
Save romainfrancois/cb7365afba88c0ec586bada4f0dfc3d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
library(dplyr) | |
library(purrr) | |
library(rlang) | |
derange <- function(data, ..., by_group = FALSE){ | |
arrange( data, !!!map( quos(...), ~ quo(desc(!!.)) ), by_group = by_group ) | |
} | |
d <- data.frame( x = 1:10, y = letters[1:10]) | |
derange(d, x, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
derange <- function(data, ..., by_group = FALSE){
if(by_group){
dplyr::arrange( data, !!!map( quos(...), ~ quo(desc(!!.)) ), .by_group = TRUE)
} else{
dplyr::arrange( data, !!!map( quos(...), ~ quo(desc(!!.)) ))
}
}
d <- data.frame( x = 1:10, y = letters[1:10])
dg <- d %>% group_by(y)
derange(d, x, y)
derange(dg, x, y)
derange(dg, x, y, by_group = TRUE)