在另一个时间范围内返回数据子集时间范围?

编程入门 行业动态 更新时间:2024-10-11 07:27:16
本文介绍了在另一个时间范围内返回数据子集时间范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

子集xts 对象有非常漂亮的方法.例如,您可以通过以下方式获取所有年、月、日的所有数据,但严格限制在上午 9 点 30 分到下午 4 点之间:

There are very nifty ways of subsetting xts objects. For example, one can get all the data for all years, months, days but being strictly between 9:30 AM and 4 PM by doing:

my_xts["T09:30/T16:00"]

或者您可以通过执行以下操作获取两个日期之间的所有观察值:

Or you can get all the observations between two dates by doing:

my_xts["2012-01-01/2012-03-31"]

或者通过执行以下操作来获取某个日期之前/之后的所有日期:

Or all the dates before/after a certain date by doing:

my_xts["/2011"] # from start of data until end of 2011 my_xts["2011/"] # from 2011 until the end of the data

我如何才能获得所有年份中特定月份的所有数据或所有月份和年份中仅特定日期的所有数据?是否存在任何其他子集化技巧?

How can I get all the data for only certain months for all years or only certain days for all months and years? Do any other subsetting tricks exist?

推荐答案

您可以使用 .index* 系列函数来获取特定月份或特定日期.有关完整的函数列表,请参阅 ?index.例如:

You can use the .index* family of functions to get certain months or certain days of the month. See ?index for the full list of functions. For example:

library(quantmod) getSymbols("SPY") SPY[.indexmon(SPY)==0] # January for all years (note zero-based indexing!) SPY[.indexmday(SPY)==1] # The first of every month SPY[.indexwday(SPY)==1] # All Mondays

更多推荐

在另一个时间范围内返回数据子集时间范围?

本文发布于:2023-11-07 19:22:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567205.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间   子集   范围内   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!