用R Lubridate提取会计年度 [英] Extract Fiscal Year with R Lubridate

查看:68
本文介绍了用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆