How do I group my date variable into month/year in R?

The floor_date() function from the lubridate package does this nicely.

data %>% 
    group_by(month = lubridate::floor_date(date, "month")) %>%
    summarize(summary_variable = sum(value))

Thanks to Roman Cheplyaka
https://ro-che.info/articles/2017-02-22-group_by_month_r

See more on how to use the function: https://lubridate.tidyverse.org/reference/round_date.html

Leave a Comment