-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
featurea feature request or enhancementa feature request or enhancementrows ↕️Operations on rows: filter(), slice(), arrange()Operations on rows: filter(), slice(), arrange()
Description
I would like to be able to order_by multiple columns when using either slice_min() or slice_max().
This would hopefully feed into dbplyr and this feature request tidyverse/dbplyr#765
library(dplyr, warn.conflicts = FALSE)
# Create dummy table
(df <- tibble(
col_1 = c(1, 2, 1, 2, 1, 2, 1, 2),
col_2 = c(2, 1, 0, 3, 2, 1, 0, 1)
))
#> # A tibble: 8 × 2
#> col_1 col_2
#> <dbl> <dbl>
#> 1 1 2
#> 2 2 1
#> 3 1 0
#> 4 2 3
#> 5 1 2
#> 6 2 1
#> 7 1 0
#> 8 2 1
df %>%
slice_max(order_by = c(col_1, -col_2))
#> # A tibble: 4 × 2
#> col_1 col_2
#> <dbl> <dbl>
#> 1 2 1
#> 2 2 3
#> 3 2 1
#> 4 2 1
df %>%
slice_max(order_by = c(col_1, desc(col_2)))
#> # A tibble: 4 × 2
#> col_1 col_2
#> <dbl> <dbl>
#> 1 2 1
#> 2 2 3
#> 3 2 1
#> 4 2 1Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featurea feature request or enhancementa feature request or enhancementrows ↕️Operations on rows: filter(), slice(), arrange()Operations on rows: filter(), slice(), arrange()