rdateas.date

Convert "Year-Quarter" to date format in R?


How can I convert the following vector in R to an as.Date format?

date= c( "2023-Q3" ,"2021-Q1", "2017-Q1", "2009-Q1", "2001-Q1", "1988-Q4")

Solution

  • Use the yq function from lubridate. This will give you the first date of the first month of the quarter

    lubridate::yq(date)
    [1] "2023-07-01" "2021-01-01" "2017-01-01" "2009-01-01" "2001-01-01" "1988-10-01"