我使用lubridate并认为这会很容易ymd("2010-01-31")+months(0:23)但是,看看有什么。都搞砸了! [1] "2010-01-31 UTC" "2010-03-03 UTC" "2010-03-31 UTC" "2010-05-01 UTC" "2010-05-31 UTC" "2010-07-01 UTC" "2010-07-31 UTC" "2010-08-31 UTC" "2010-10-01 UTC"[10] "2010-10-31 UTC" "2010-12-01 UTC" "2010-12-31 UTC" "2011-01-31 UTC" "2011-03-03 UTC" "2011-03-31 UTC" "2011-05-01 UTC" "2011-05-31 UTC" "2011-07-01 UTC"[19] "2011-07-31 UTC" "2011-08-31 UTC" "2011-10-01 UTC" "2011-10-31 UTC" "2011-12-01 UTC" "2011-12-31 UTC"然后,我阅读了润滑如何满足间隔,持续时间和周期等现象。所以,好的,我意识到一个月实际上是(365 * 4 + 1)/ 48 = 30.438天定义的天数。所以我试图变得聪明,并将其重写为ymd("2010-01-31")+ as.period(months(0:23))但这只是一个错误。Error in as.period.default(months(0:23)) : (list) object cannot be coerced to type 'double'
2 回答
明月笑刀无情
TA贡献1828条经验 获得超4个赞
令人惊讶的是,输入问题会集中精力发挥创造力。我想我已经解决了。我不妨在这里张贴给下一个发现自己在浪费时间的可怜的灵魂。
ymd("2010-02-01")+ months(0:23)-days(1)
只需指定下个月的第一天并从中生成一个序列,但从中减去1天即可得到上个月的最后一天。
[1] "2010-01-31 UTC" "2010-02-28 UTC" "2010-03-31 UTC" "2010-04-30 UTC" "2010-05-31 UTC" "2010-06-30 UTC" "2010-07-31 UTC" "2010-08-31 UTC" "2010-09-30 UTC"
[10] "2010-10-31 UTC" "2010-11-30 UTC" "2010-12-31 UTC" "2011-01-31 UTC" "2011-02-28 UTC" "2011-03-31 UTC" "2011-04-30 UTC" "2011-05-31 UTC" "2011-06-30 UTC"
[19] "2011-07-31 UTC" "2011-08-31 UTC" "2011-09-30 UTC" "2011-10-31 UTC" "2011-11-30 UTC" "2011-12-31 UTC"
顺便说一句,我如何摆脱讨厌的“ UTC”称号。时区在需要时可以节省生命。其余的时间他们很讨厌。
- 2 回答
- 0 关注
- 628 浏览
添加回答
举报
0/150
提交
取消