使用R的xts中的端点 [英] endpoints in xts using R
问题描述
我试图弄清楚endpoints
如何选择我的数据仅具有弱规律性的时间:也就是说,缺少一些观察结果.我有1分钟的退货时间,但有几分钟的时间缺失,我正尝试转换为5分钟的间隔. endpoints
将如何决定保留哪些时间?我使用的电话是:
I am trying to figure out how endpoints
selects the times when my data is only weakly regular: that is, some observations are missing. I have 1 minute returns with some minutes missing and I am trying to convert to 5 minute intervals. How will endpoints
decide which times to keep? The call I use is:
endpoints(ret_1_min_xts, k=5, "minutes")
我的系列如下所示:
1986-02-04 09:32:00 1
1986-02-04 09:33:00 2
1986-02-04 09:34:00 3
1986-02-04 09:35:00 4
1986-02-04 09:36:00 5
1986-02-04 09:37:00 6
1986-02-04 09:38:00 7
1986-02-04 09:39:00 8
1986-02-04 09:40:00 9
1986-02-04 09:41:00 10
1986-02-04 09:42:00 11
1986-02-04 09:45:00 12
...
调用endpoints
返回:
1986-02-04 09:34:00
1986-02-04 09:39:00
1986-02-04 09:42:00
1986-02-04 09:49:00
1986-02-04 09:54:00
...
我正在尝试查看endpoints
的源代码,但似乎该函数在C语言中,并且是通过.Call
调用的;我理解正确吗?如果有人可以解释所使用的方法,那将非常有帮助.
I am trying to look at the source code of endpoints
but it seems that the function is in C and is called via .Call
; am i understanding that correctly? if someone could explain the methodology used, that would be very helpful.
推荐答案
如上面的注释所述,直接从endpoints.c源代码获取,该函数返回以下内容:
as answered in the comments above and taken directly from the endpoints.c source code, the function returns this:
c(0,which(diff(_x%/%on%/%k+1) != 0),NROW(_x))
其中_x = .index(my_xts)
这实际上是做什么的?关于我对endpoints
函数的调用:
what does this actually do? with respect to my call of the endpoints
function:
diff
中的内容首先删除秒数,然后将其移动到k分钟的增量(所有这些都使用整数除法).然后diff
只需记下更改为下一个增量的点,然后which
返回发生增量的点.实际上,这只是返回每5分钟间隔的最后一个点(我的通话中k = 5)
the stuff inside diff
first removes the seconds and then moves things into k minute increments (all this using integer division). diff
then simply notes the points where you change to the next increment and which
returns those points where the increment occurs. in effect this simply returns the last point in each 5 minute interval (k=5 in my call)
这篇关于使用R的xts中的端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!