2018年9月10日月曜日

mondate,as.yearmon and the calculation to treat number of months. mondate as.yearmon as.yearqtr as.Date(date,frac=1) 該当月の初めの日付



> index(last(G))
[1] "2018-04-01"
> mondate(index(last(G)))+2
mondate: timeunits="months"
[1] 2018-06-01
> as.yearmon(as.character(mondate(index(last(G)))+2))
[1] " 6 2018"
> as.yearmon((mondate(index(last(G)))+2))
[1] " 6 2018"
> as.yearmon(mondate(index(last(G))+2))
[1] " 4 2018"
> as.yearmon((mondate(index(last(G)))+2))
[1] " 6 2018"
> as.Date(as.yearmon((mondate(index(last(G)))+2)),frac=1)
[1] "2018-06-30"
>
> paste("1992-01-01::",as.Date(as.yearmon((mondate(index(last(G)))+2)),frac=1),sep="")
[1] "1992-01-01::2018-06-30"
> kikan <- paste("1992-01-01::",as.Date(as.yearmon((mondate(index(last(G)))+2)),frac=1),sep="")
# calculate coming quarter beginning dates
> as.Date(as.yearqtr((mondate(index(last(G)))+seq(3,27,3))))
[1] "2018-07-01" "2018-10-01" "2019-01-01" "2019-04-01" "2019-07-01" "2019-10-01" "2020-01-01" "2020-04-01" "2020-07-01"
> as.Date(as.yearmon(mondate(index(last(CS)))+seq(1,48,1)),frac=0)
 [1] "2018-07-01" "2018-08-01" "2018-09-01" "2018-10-01" "2018-11-01" "2018-12-01" "2019-01-01" "2019-02-01" "2019-03-01"
<skip>
[46] "2022-04-01" "2022-05-01" "2022-06-01"
> as.Date(as.yearqtr(mondate(index(last(CS)))+seq(3,48,3)),frac=0)
 [1] "2018-07-01" "2018-10-01" "2019-01-01" "2019-04-01" "2019-07-01" "2019-10-01" "2020-01-01" "2020-04-01" "2020-07-01"
[10] "2020-10-01" "2021-01-01" "2021-04-01" "2021-07-01" "2021-10-01" "2022-01-01" "2022-04-01"


kikan <- paste("1992-01-01::",as.Date(as.yearmon((mondate(index(last(G)))+2)),frac=1),sep="")
k2k <- paste("2000-01-01::",as.Date(as.yearmon((mondate(index(last(G)))+2)),frac=1),sep="")

0 件のコメント: