【发布时间】:2021-04-09 06:35:55
【问题描述】:
我有初步的每月签证数据(2017 年 9 月 - 2020 年 11 月),我想将其与官方公布的财政年度数据进行比较。我将月份存储为 yearmon 对象,并希望在新列中标识联邦财政年度(从 10 月开始)。
我可以很容易地用下面的代码做到这一点:
library(tidyverse)
library(zoo)
IVdata_FY <- IVdata_final %>%
mutate(
fy = case_when(
month <= "Sep 2017" ~ "FY17",
month >= "Oct 2017" & month <= "Sep 2018" ~ "FY18",
month >= "Oct 2018" & month <= "Sep 2019" ~ "FY19",
month >= "Oct 2019" & month <= "Sep 2020" ~ "FY20",
month >= "Oct 2020" ~ "FY21"
)
)
但是,如果我有跨越多个财政年度的数据,那么这种手动方法会过度且容易出错。
有没有一种简单的方法来确定财政年度,而不必详细说明每个财政年度的时间范围?我的预感是它会涉及到 zoo 如何存储 yearmon 数据,但我一直无法弄清楚我可以使用什么代码。
【问题讨论】: