I have date values contained in text, each containing a half of the year:
date_by_half <- c("2016 H1", "2017 H2", "2018 H1")
I'd like to extract the date from text and store as the first day of each half or "semester". So, something like:
ysemester(date_by_half)
#[1] "2016-01-01" "2017-07-01" "2018-01-01"
I'm familiar with lubridate::yq() function, but I found that this only works for quarters.
lubridate::yq(date_by_half)
#[1] "2016-01-01" "2017-04-01" "2018-01-01"
Right now my work around is to replace H2 with Q3:
lubridate::yq(stringr::str_replace(date_by_half,"H2", "Q3"))
#[1] "2016-01-01" "2017-07-01" "2018-01-01"
However, I'm wondering if there is a more eloquent solution using lubridate (or some other quick and reusable method).