本文介绍了在R中生成一个月的最后一天的日期序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我给出开始日期和结束日期以及频率,我应该能够生成从开始到结束的一系列日期,这样

If I give a start date and end date, and a frequency I should be able to generate a sequence of dates from start to end such that

1)不在该月底用

替换 as.yearmon(st)

Similarly if st is a date and the starting date of the sequence should be no later than st use the same idea to subtract 1/12 if st is not at the end of the month replacing as.yearmon(st) with

as.yearmon(st) - (as.Date(st) < as.Date(as.yearmon(st), frac = 1)) / 12

我们是否真的需要日期,这是一个疑问,因为它们总是在月底.似乎关键是要创建一个年/月序列,而月末日期只是表示该序列的一种方式.一种更简单的方法是直接将此 yearmon 序列.

There is some question regarding whether we really need dates at all since they are always at the end of the month. It seems that the point is to create a year/month sequence and the end-of-month dates are just a way to represent that. A simpler way would be this yearmon sequence directly.

seq(as.yearmon(st), as.yearmon(en), by = 1 / freq)

这篇关于在R中生成一个月的最后一天的日期序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 16:53
查看更多