2016年5月18日水曜日

how to add an entiry into XTS class.

> class(GDP_XTS)
[1] "xts" "zoo"
> last(GDP_XTS,n=4)[,1]
2015-10-01 16470.57
2015-11-01 16477.96
2015-12-01 16485.35
2016-01-01 16492.75

add an entry with index. this sample uses the index as "2016-02-01". data might be just garbage.

> last(append(GDP_XTS,c(as.Date("2016-02-01"))))[,1]
2016-02-01 2.145571e-314
> w <- append(GDP_XTS,c(as.Date("2016-02-01")))
> last(w)[,1]
2016-02-01 2.144668e-314

access entry by specifying index.

> w["2016-02-01"][,1]
2016-02-01 2.144668e-314
> w["2016-02-01"][,1] <- 16525

unable to insert a data entry where the index doesn't exit. Create the index before insert!

> w["2016-03-01"][,1] <- 16558
> last(w,n=4)[,1]
2015-11-01 16477.96
2015-12-01 16485.35
2016-01-01 16492.75
2016-02-01 16525.00
>

0 件のコメント: