用R Lubridate提取会计年度 [英] Extract Fiscal Year with R Lubridate
问题描述
我将创建几个日期.
library(lubridate)
x <- ymd(c("2012-03-26", "2012-05-04", "2012-09-23", "2012-12-31"))
我可以从这些x
值中提取年份和季度.
I can extract the year and quarter from these x
values.
quarter(x, with_year = TRUE, fiscal_start = 10)
[1] 2012.2 2012.3 2012.4 2013.1
但是我似乎无法提取公正会计年度.这不起作用,但是会怎样?
But I can't seem to extract just the fiscal year. This doesn't work, but what will?
year(x, with_year = TRUE, fiscal_start = 10)
我收到以下错误消息:
year(x,with_year = TRUE,financial_start = 10)中的错误: 未使用的参数(with_year = TRUE,fiance_start = 10)
Error in year(x, with_year = TRUE, fiscal_start = 10) : unused arguments (with_year = TRUE, fiscal_start = 10)
推荐答案
如果您不介意执行其他步骤,则可以提取季度的前4个字符以得出年份.
If you don't mind an additional step, you could then extract the first 4 characters of your quarters to get just the years.
library(lubridate)
x <- ymd(c("2012-03-26", "2012-05-04", "2012-09-23", "2012-12-31"))
q <- quarter(x, with_year = TRUE, fiscal_start = 10)
q
#> [1] 2012.2 2012.3 2012.4 2013.1
fy <- stringr::str_sub(q, 1, 4)
fy
#> [1] "2012" "2012" "2012" "2013"
这篇关于用R Lubridate提取会计年度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!