计算下一个季度何时开始
看看这个:
> as.Date("2000-01-01")+months(1)
[1] "2000-02-01"
> as.Date("2000-01-01")+months(3)
[1] "2000-04-01"
> as.Date("2000-01-01")+months(24)
[1] "2002-01-01"
我想要相同的但对于季度,当我将 p
季度添加到日期时,我想知道下一个季度的开始日期,如下所示,但我收到此错误:
as.Date("2000-01-01")+quarters(1)
UseMethod("quarters") 中的错误:没有适用的方法 'quarters' 应用于类“c('double', 'numeric')”的对象
我该怎么做?我确实需要使用与 months()
不同的东西。
Have a look at this:
> as.Date("2000-01-01")+months(1)
[1] "2000-02-01"
> as.Date("2000-01-01")+months(3)
[1] "2000-04-01"
> as.Date("2000-01-01")+months(24)
[1] "2002-01-01"
I want the same but for quarters, I want to know the date the next quarter starts when I add p
quarters to a date, like this, but I get this error:
as.Date("2000-01-01")+quarters(1)
Error in UseMethod("quarters") : no applicable method for
'quarters' applied to an object of class "c('double', 'numeric')"
How can I do it? I really need to use something different from months()
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为此使用时钟的
year_quarter_day
类。这是它设计的东西之一。如果您真的只是在寻找下一个季度的开始,那么最强大的事情是:更改为季度精度,添加四分之一,将一天设置为1,迄今为止转换。
You can use clock's
year_quarter_day
class for this. It is one of the things it was designed for.If you are really just looking for the start of the next quarter, the most robust thing to do is to: change to a quarterly precision, add a quarter, set the day to 1, convert back to date.