I have preliminary monthly visa data (September 2017 - November 2020) that I want to compare with the official, published fiscal year numbers. I have the month stored as a yearmon object and want to identify the federal fiscal year (begins in October) in a new column.
I was able to do so easily enough with the following code:
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" ) )
However, if I had data spanning more fiscal years this by-hand approach would be excessive and prone to mistakes.
Is there a simple way to identify the fiscal year without having to spell out the time frames for each one? My hunch is that it would involve how zoo stores the yearmon data, but I haven't been able to figure out what code I could use.
https://stackoverflow.com/questions/65546225/identify-fiscal-year-for-yearmon-object-in-r January 03, 2021 at 10:52AM
没有评论:
发表评论