Slice - dsofe/coderr GitHub Wiki

slice

https://dplyr.tidyverse.org/reference/slice.html

slice_min() and slice_max() to get the records that match values; can request a list of, e.g., "top 5"

# tibble with four cases
df <- tibble(x = 1:4, y = 4:1)

# subset, first 2 cases
df1 <- df %>%
  slice_min(x, n = 2)  # instead of filter(x <= 2)
# `n = 2` to fetch the 2 cases with the lowest values on x

# subset, other 2 cases
df2 <- df %>%
  slice_max(x, n = 2)  # instead of filter(x > 2)
# `n = 2` to fetch the 2 cases with the highest values on x
⚠️ **GitHub.com Fallback** ⚠️