0

我想使用两个季度之间所有季度的列表,在变量中设置为字符。但我得到一个错误。

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

1 回答 1

0

我不确定是否seq接受季度格式,因此您转换为日期格式并转换回季度:

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"
于 2022-03-04T09:53:07.813 回答