Home > database >  seq create list quarters R
seq create list quarters R

Time:03-04

I want to use the list of all quarters between two quarters, set in variables as characters. But I get an error.

timeMin <- "2015Q1"
dissemPeriod <- "2022Q1"
list(seq(as.yearqtr(timeMin),as.yearqtr(dissemPeriod),by="quarter"))
Error in del/by : non-numeric argument to binary operator

CodePudding user response:

I'm not sure seq accepts quarter format, so you convert to date format and convert back to quarter:

library(zoo)
timeMin <- as.Date(as.yearqtr("2015Q1"))
dissemPeriod <- as.Date(as.yearqtr("2022Q1"))
as.yearqtr(seq(timeMin, dissemPeriod, by="quarter"))

# [1] "2015 Q1" "2015 Q2" "2015 Q3" "2015 Q4" "2016 Q1" "2016 Q2" "2016 Q3" "2016 Q4" "2017 Q1" "2017 Q2"
# [11] "2017 Q3" "2017 Q4" "2018 Q1" "2018 Q2" "2018 Q3" "2018 Q4" "2019 Q1" "2019 Q2" "2019 Q3" "2019 Q4"
# [21] "2020 Q1" "2020 Q2" "2020 Q3" "2020 Q4" "2021 Q1" "2021 Q2" "2021 Q3" "2021 Q4" "2022 Q1"
  • Related