2019年2月6日水曜日

index mondate,merge



>  index(bp.day["2019"])
 [1] "2019-01-03 UTC" "2019-01-04 UTC" "2019-01-05 UTC" "2019-01-06 UTC" "2019-01-07 UTC" "2019-01-08 UTC"
 [7] "2019-01-09 UTC" "2019-01-10 UTC" "2019-01-11 UTC" "2019-01-12 UTC" "2019-01-13 UTC" "2019-01-14 UTC"
<skip>
[31] "2019-02-02 UTC" "2019-02-03 UTC" "2019-02-04 UTC" "2019-02-05 UTC"

>  mondate(index(bp.day["2019"]))-12
mondate: timeunits="months"
 [1] 2018-01-03 2018-01-04 2018-01-05 2018-01-06 2018-01-07 2018-01-08 2018-01-09 2018-01-10 2018-01-11 2018-01-12
<skip>
[31] 2018-02-02 2018-02-03 2018-02-04 2018-02-05

> as.character(mondate(index(bp.day["2019"]))-12)
 [1] "2018-01-03" "2018-01-04" "2018-01-05" "2018-01-06" "2018-01-07" "2018-01-08" "2018-01-09" "2018-01-10"
<skip>
[25] "2018-01-27" "2018-01-28" "2018-01-29" "2018-01-30" "2018-01-31" "2018-02-01" "2018-02-02" "2018-02-03"
[33] "2018-02-04" "2018-02-05"

>  bp.day[as.character(mondate(index(bp.day["2019"]))-12)]
               high       low
2018-01-03 147.0000 100.00000
2018-01-04 150.0000 104.00000
2018-01-05 131.0000  87.50000
2018-01-06 143.0000 108.00000
<skip>
2018-02-03 148.0000  91.00000
2018-02-04 124.3333  77.00000

> bp.day["2019"]
            high  low
2019-01-03 130.0 78.0
2019-01-04 136.0 80.0
2019-01-05 129.0 83.0
2019-01-06 127.0 77.5
<skip>
2019-02-03 117.5 75.5
2019-02-04 119.0 76.5
2019-02-05 116.5 71.0

merge them and draw graph.
the code below doesn't work when the data exits on the particular date which exits in 2019 but not in 2018.

> bp.day["2019-02-11"]
           high  low
2019-02-11  126 77.5
> bp.day["2018-02-11"]
     high low

updated code is available at 2019-02-17. please refer the new code.

bp.day <- apply.daily(bp.bangkok,mean)
merge(bp.day["2019"], as.vector(bp.day[as.character(mondate(index(bp.day["2019"]))-12)][,1]), as.vector(bp.day[as.character(mondate(index(bp.day["2019"]))-12)][,2]),suffixes=c("","h2018","l2018"))

0 件のコメント: