Access zoo or xts index

匆匆过客 提交于 2019-11-28 08:59:41

From the help for ?zoo, there are two convenience methods to access the data in zoo objects:

  • coredata() returns the data in the zoo object
  • index() returns the index

For example:

x.Date <- as.Date("2003-02-01") + c(1, 3, 7, 9, 14) - 1
x <- zoo(rnorm(5), x.Date)

index(x)
[1] "2003-02-01" "2003-02-03" "2003-02-07" "2003-02-09" "2003-02-14"

coredata(x)
[1] -1.2487943  0.8911630  1.2713133 -0.1024638  0.2989194

In general when you see attr, this means that this data is an attribute of an object.

attributes function can be used to dump all attributes as a list, so you can access certain element with $:

attributes(ObjZoo)$index

attr gives you direct access to the attribute by its name:

attr(ObjZoo,"index")

In fact this is what index does:

> zoo:::index.zoo

function (x, ...) 
{
    attr(x, "index")
}
<environment: namespace:zoo>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!