2017年3月24日金曜日

Calculate the first and the last day of any designated month.

Below will pick up the start and the end of next month where PA data ends.


as.Date(as.yearmon(mondate(index(last(PA)))+1))
[1] "2017-03-01"
as.Date(as.yearmon(mondate(index(last(PA)))+2))-1
[1] "2017-03-31"


thus the combination of them will output as below.


as.xts(forecast(auto.arima(PA),h=10)$mean[1:10],as.Date(seq(mondate(index(last(PA)))+1,by=1,length.out=10)))

               [,1]
2017-03-02 145989.9
2017-04-02 146182.0
      <SKIP>
2017-11-02 147361.8

2017-12-02 147513.5


pick up the first day and the last day of the month which is exactly 36 months after any given date.

> as.Date(as.yearmon((mondate(Sys.Date())+36)))
[1] "2020-03-01"


> as.Date(as.yearmon((mondate(Sys.Date())+36)))-1
[1] "2020-02-29"
>

do the same thing by ISOdate, however it's much more redundant.

> as.Date(ISOdate(yea(mondarte(.())SysDate+36),month(mondate(Sys.Date())+36),1))-1
[1] "2020-02-29"

0 件のコメント: