R: xts 对象 - 确定第一个数据点的日期
我有大量时间序列变量(股票价格),我想对其执行各种分析。问题在于,并非所有变量在我感兴趣的数据范围内都具有相同数量的价格,因为有些股票是在不同的时间点出现的。
因此,我试图返回每个 xts 变量中第一个数据元素的日期,但目前我有一个非常丑陋的解决方案来执行此操作。我想知道是否有一个函数可以调用以通过某种索引返回日期。
例如,
> str(IBM)
An ‘xts’ object from 2004-01-02 to 2011-04-25 containing:
Data: num [1:1841, 1] 25.1 25.6 25.6 25.3 25.4 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr "IBM.Adjusted"
Indexed by objects of class: [Date] TZ:
xts Attributes:
List of 2
$ src : chr "yahoo"
$ updated: POSIXct[1:1], format: "2011-04-26 14:35:02"
我正在寻找一种干净的方法来从上面的对象中获取 2004-01-02 。
我很感激你的帮助。谢谢。
I have a large number of time series variables (stock prices) of which I want to perform various analytics. The problem is not all variables have same number of prices in the data range I am interested in using because some stocks came into existence at different points in time.
As such, I am trying to return the date of the first data element in each of the xts variables but I have a very ugly solution to do this at the moment. I was wondering if there is a function that I could call to return the date by some sort of indexing.
i.e
> str(IBM)
An ‘xts’ object from 2004-01-02 to 2011-04-25 containing:
Data: num [1:1841, 1] 25.1 25.6 25.6 25.3 25.4 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr "IBM.Adjusted"
Indexed by objects of class: [Date] TZ:
xts Attributes:
List of 2
$ src : chr "yahoo"
$ updated: POSIXct[1:1], format: "2011-04-26 14:35:02"
I am looking for a clean way to grab 2004-01-02 from the above object for example.
I appreciate the help. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想这会起作用:
I imagine this would work:
您可以使用
start
函数:You can use the
start
function: