0

I have a dataframe that is already Fiscal Year data (year+month, assuming every July 1 of current calendar year is next Fiscal Year ), wish to convert back to calendar year + month in R.

My original fiscal year data is 'ddd', type is Date()

ddd [1] "2022-11-01" "2022-06-04" "2022-07-04"

I wish to use ifelse() function to convert it, and avoid using loops for considering I have larger dataframe to implement in future. If the month is after Jun, shift Fiscal Year's year backwards 12 months.

eee<- (ifelse(month(ddd)>6, (ddd%m+%months(-12)), ddd))

but it shows

eee [1] 18932 19147 18812.

I guess those are month number from 1960 ?! I thought I need to coerce the datatype as eee is shown to be erroneously numeric type. so I tried eee<- (ifelse(month(ddd)>6, as.Date(ddd%m+%months(-12)), as.Date(ddd))) , the result is the same.

I expect to get "2021-11-01" "2022-06-04" "2021-07-04" Thanks !

Ivan
  • 1
  • 1

0 Answers0