XTS apply function to time of day subset?

感情迁移 提交于 2019-12-01 07:24:52

问题


How can I apply a summary function to a time of day subset?

For example with:

r['T16:00/T17:00']$Value

How can I apply something like function (x) quantile(x, c(.90)) for Value over each day's sample hour?


回答1:


You can use apply.daily to apply a function to each day's data after you've done the time-of-day subset.

rt <- r['T16:00/T17:00','Value']
rd <- apply.daily(rt, function(x) xts(t(quantile(x,0.9)), end(x)))

You can see I needed to do a few backflips to ensure the object returned from your function can be handled by apply.daily. Mainly, it has to be a multi-column xts object with one row.



来源:https://stackoverflow.com/questions/9087361/xts-apply-function-to-time-of-day-subset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!