Skip to main content
100%

Function for assigning a date to a bi-annual period: Useful when needing to group dates into a period for time-series visualisation

✓ Published0🌍 Public
JJustinCally
Last edited Aug 19, 2019
Created on Aug 19, 2019

This visualization example demonstrates a utility function for converting individual dates into bi-annual period groupings, a preprocessing step for time-series analysis. The function uses `lubridate`'s `dmy`, `year`, and `floor_date` functions to compare each input date against two fixed cutpoints (June 30th and December 31st), then returns the first day of the month for the appropriate six-month period. Dates falling after the second cutpoint are assigned to the following year’s first period, ensuring all data maps to a two-category annual cycle. The code explicitly handles year boundaries through conditional `ifelse` logic.

AI-generated description

Similar vizzes