XTS 将函数应用于一天中的时间子集? [英] XTS apply function to time of day subset?
本文介绍了XTS 将函数应用于一天中的时间子集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将汇总函数应用于一天中的时间子集?
How can I apply a summary function to a time of day subset?
例如:
r['T16:00/T17:00']$Value
如何在每天的样本小时内应用 function (x) quantile(x, c(.90))
之类的值?
How can I apply something like function (x) quantile(x, c(.90))
for Value over each day's sample hour?
推荐答案
在完成时间子集后,您可以使用 apply.daily
将函数应用于每天的数据.
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)))
你可以看到我需要做一些后空翻以确保从你的函数返回的对象可以被 apply.daily
处理.主要是,它必须是一个多列 xts 对象,一行.
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.
这篇关于XTS 将函数应用于一天中的时间子集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文