Skip to content

Instantly share code, notes, and snippets.

@brshallo
Created May 9, 2022 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brshallo/4cdce482e1cd33edaa9575e1e3f1633b to your computer and use it in GitHub Desktop.
Save brshallo/4cdce482e1cd33edaa9575e1e3f1633b to your computer and use it in GitHub Desktop.
library(tidyverse)
library(lubridate)

tibble(
  group = c("a", "a", "b", "b"),
  dates = ymd(c("2020-01-01", "20220207", "20220209", "20220115"))
) %>%
  group_by(group) %>% 
  summarise(date_range = list(range(dates) %>% 
                                set_names("min", "max"))) %>% 
  unnest_wider(date_range)
#> # A tibble: 2 x 3
#>   group min        max       
#>   <chr> <date>     <date>    
#> 1 a     2020-01-01 2022-02-07
#> 2 b     2022-01-15 2022-02-09

Created on 2022-05-09 by the reprex package (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment